递归实现如下:

    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
if(p.val>root.val&&q.val>root.val)
return lowestCommonAncestor(root.right,p,q);
else if(p.val<root.val&&q.val<root.val)
return lowestCommonAncestor(root.left,p,q);
return root;
}

Java for LeetCode 235 Lowest Common Ancestor of a Binary Search Tree的更多相关文章

  1. leetcode 235. Lowest Common Ancestor of a Binary Search Tree 236. Lowest Common Ancestor of a Binary Tree

    https://www.cnblogs.com/grandyang/p/4641968.html http://www.cnblogs.com/grandyang/p/4640572.html 利用二 ...

  2. [LeetCode] 235. Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  3. [LeetCode] 235. Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  4. Java [Leetcode 235]Lowest Common Ancestor of a Binary Search Tree

    题目描述: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in ...

  5. LeetCode 235. Lowest Common Ancestor of a Binary Search Tree (二叉搜索树最近的共同祖先)

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  6. leetcode 235. Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  7. (easy)LeetCode 235.Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  8. Leetcode 235 Lowest Common Ancestor of a Binary Search Tree 二叉树

    给定一个二叉搜索树的两个节点,找出他们的最近公共祖先,如, _______6______ / \ ___2__ ___8__ / \ / \ 0 4 7 9 / \ 3 5 2和8的最近公共祖先是6, ...

  9. 【LeetCode】235. Lowest Common Ancestor of a Binary Search Tree (2 solutions)

    Lowest Common Ancestor of a Binary Search Tree Given a binary search tree (BST), find the lowest com ...

随机推荐

  1. php 冒泡排序

    public function demo($arr){ $len = count($arr); if ($len == 1) { return $arr; } else { for ($i = 1; ...

  2. Excel 使用宏批量修改单元格内指定文字为红字

    -> step 1:新建宏,进入编辑,使用如下代码: Sub Ss()Dim c As RangeFor Each c In ActiveSheet.UsedRange i = 1 While ...

  3. resin

    http://blog.csdn.net/sea0x/article/details/6097531 resin 启动: resin 配置文件摘取: <server-default> &l ...

  4. WP8.1下 Cortana语音命令 VCD文件 设计

    Windows Phone8.1下的Cortana,可以通过语音的方式,打开.设置应用,进行页面跳转.执行任务. 我们先要创建VCD(VoiceCommand.xml)文件 <?xml vers ...

  5. 关于QString::toWCharArray 无法解析的外部符号

    1>CommManger.obj : error LNK2019: 无法解析的外部符号 "public: int __thiscall QString::toWCharArray(un ...

  6. mybatis 多个dao重名,根据namespace解析

    在mybatis通过执行sql语句的方式是,用getSqlSession().xxx(param,..)方法来调用, 其中第一个参数就是dao mapper.xml文件的命名空间.id package ...

  7. 被拒原因——You have selected the Kids Category for your app, but it does not include the required privacy policy. Please update your app metadata to include a privacy policy URL and ensure that the URL yo

    对于一些孩子类的应用,必须加上隐私政策网址(URL),直接截个图吧! 就是你上架的时候,填写应用信息,里面有一个隐私政策网址(URL),望后者不掉坑里了!!!

  8. LR常用函数整理

    1,变量转参数lr_save_string("aaa","param"):将字符串"aaa"或者一个字符串变量,转变成LR的参数{param ...

  9. xcode 插件

    http://www.cocoachina.com/ios/20160122/15080.html https://github.com/rickytan/RTImageAssets http://m ...

  10. windows 下wamp环境2 配置之mysql的安装

    安装配置mysql 5.7 打开mysql官网: https://www.mysql.com/ 点击downloads,然后选择commuity 选择MySQL Community Server选择对 ...