码迷,mamicode.com
首页 > 其他好文 > 详细

235. Lowest Common Ancestor of a Binary Search Tree

时间:2018-09-02 23:44:12      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:nbsp   code   bsp   solution   身体   stc   mon   turn   ret   

身体不好

 

 1 class Solution {
 2     public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
 3         if(p.val < root.val && q.val < root.val) {
 4             return lowestCommonAncestor(root.left, p , q);
 5         }else if(p.val > root.val && q.val > root.val) {
 6             return lowestCommonAncestor(root.right, p , q);
 7         }else {
 8             return root;
 9         }   
10     } 
11 }

 

235. Lowest Common Ancestor of a Binary Search Tree

标签:nbsp   code   bsp   solution   身体   stc   mon   turn   ret   

原文地址:https://www.cnblogs.com/goPanama/p/9575485.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!