**LeetCode-Lowest Common Ancestor of a Binary Tree
来源:互联网 发布:linux grep命令与管道 编辑:程序博客网 时间:2024/05/24 00:10
假如访问到一点 等于其中某一个node 那就返回这个node
都不等于就分别访问左右子树 左右两边假如返回的都不是null 那么lca就是root
假如一个是null 那lca就是另一个
其实还没想清楚
public class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if ( root == null || root == p || root == q) return root; TreeNode left = lowestCommonAncestor ( root.left, p, q ); TreeNode right = lowestCommonAncestor( root.right, p, q); if ( left != null && right != null ) return root; return left != null ? left : right; }}
0 0
- leetcode 235: Lowest Common Ancestor of a Binary Search Tree
- leetcode - Lowest Common Ancestor of a Binary Tree
- LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
- leetcode: Lowest Common Ancestor of a Binary Search Tree
- [leetcode][dfs] Lowest Common Ancestor of a Binary Search Tree
- [leetcode] 235.Lowest Common Ancestor of a Binary Search Tree
- [leetcode] 236.Lowest Common Ancestor of a Binary Tree
- [LeetCode]236.Lowest Common Ancestor of a Binary Tree
- 【LeetCode】235 Lowest Common Ancestor of a Binary Search Tree
- 【LeetCode】236 Lowest Common Ancestor of a Binary Tree
- leetcode 236: Lowest Common Ancestor of a Binary Tree
- [LeetCode]235.Lowest Common Ancestor of a Binary Search Tree
- LeetCode OJ 之 Lowest Common Ancestor of a Binary Tree
- leetcode 235 Lowest Common Ancestor of a Binary Search Tree
- [leetcode] Lowest Common Ancestor of a Binary Search Tree
- [leetcode] Lowest Common Ancestor of a Binary Tree
- Leetcode 236 Lowest Common Ancestor of a Binary Tree
- LeetCode Lowest Common Ancestor of a Binary Search Tree
- CodeForces #322 (div2)
- C语言冒泡排序法分析及代码实现
- IIS7.0设置404错误页,返回500状态码
- 解题报告 之 CodeForces 581D Three Logos
- Android之BaseAdapter—convertView回收机制与动态控件响应
- **LeetCode-Lowest Common Ancestor of a Binary Tree
- hiho一下 第六十周
- SQLServer数据库的导入详细图解
- 使用BootStrap进行响应式布局案例
- Android模拟器加速(精华)
- Controller向View传输数据
- D3DXMatrixDecompose Sample
- 深入javascript-封装对象
- js的new Date()构造函数