235 Lowest Common Ancestor of a Binary Search Tree
来源:互联网 发布:java classloader原理 编辑:程序博客网 时间:2024/04/30 11:58
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(root==null || p==null || q==null) return null; if(Math.max(p.val, q.val) < root.val) { return lowestCommonAncestor(root.left, p, q); } else if(Math.min(p.val, q.val) > root.val) { return lowestCommonAncestor(root.right, p, q); } else return root; } }
0 0
- leetcode 235: Lowest Common Ancestor of a Binary Search Tree
- Lowest Common Ancestor of a Binary Search Tree (235)
- 【LeetCode】235 Lowest Common Ancestor of a Binary Search Tree
- leetcode 235 Lowest Common Ancestor of a Binary Search Tree
- 235-e-Lowest Common Ancestor of a Binary Search Tree
- leetcode-235-Lowest Common Ancestor of a Binary Search Tree
- leetcode[235]:Lowest Common Ancestor of a Binary Search Tree
- 235 Lowest Common Ancestor of a Binary Search Tree
- 235 Lowest Common Ancestor of a Binary Search Tree
- LeetCode 235: Lowest Common Ancestor of a Binary Search Tree
- 235 Lowest Common Ancestor of a Binary Search Tree
- [leetcode 235]Lowest Common Ancestor of a Binary Search Tree
- leetCode #235 Lowest Common Ancestor of a Binary Search Tree
- [LeetCode 235] Lowest Common Ancestor of a Binary Search Tree
- Leetcode 235 Lowest Common Ancestor of a Binary Search Tree
- Leetcode #235 Lowest Common Ancestor of a Binary Search Tree
- LeetCode(235) Lowest Common Ancestor of a Binary Search Tree
- leetcode 235: Lowest Common Ancestor of a Binary Search Tree
- 2015 Multi-University Training Contest 1 Hdu 5297 Y sequence
- 虚函数的实现原理
- ZooKeeper安装笔记
- 学习知识
- lx-0721-1002首字母变大写
- 235 Lowest Common Ancestor of a Binary Search Tree
- java同步和中断
- lx-0721-1003统计元音
- windows install cython error: "unable to find vcvarsall.bat"
- java 线程死锁
- Cookie应用实例
- 【原创】机器学习算法之:决策树
- 基于Multisim的boost升压斩波电路仿真
- 数据结构和设计模式05(字符串)