【LeetCode-236】Lowest Common Ancestor of a Binary Tree
来源:互联网 发布:淘宝直通车广告位几个 编辑:程序博客网 时间:2024/05/18 03:51
这道题想用寻找路径的方法来解决,但是最后没能成功ac,看了一下别人的想法,自己又走弯路了!递归完全可以额!
public class ImportantLowestCommonAncestorofaBinaryTree {public class TreeNode {int val;TreeNode left;TreeNode right;TreeNode(int x) {val = x;}}public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {if (root == null)return null;if (root == p || root == q)return root;TreeNode L = lowestCommonAncestor(root.left, p, q);TreeNode R = lowestCommonAncestor(root.right, p, q);if (L != null && R != null)return root;return L != null ? L : R;}}
0 0
- 【LeetCode】236 Lowest Common Ancestor of a Binary Tree
- leetcode 236: Lowest Common Ancestor of a Binary Tree
- Leetcode 236 Lowest Common Ancestor of a Binary Tree
- LeetCode 236 Lowest Common Ancestor of a Binary Tree
- [Leetcode 236, Medium] Lowest Common Ancestor of a Binary Tree
- leetcode[236]:Lowest Common Ancestor of a Binary Tree
- Leetcode NO.236 Lowest Common Ancestor of a Binary Tree
- Leetcode #236 Lowest Common Ancestor of a Binary Tree
- [leetcode 236]Lowest Common Ancestor of a Binary Tree
- LeetCode 236 Lowest Common Ancestor of a Binary Tree
- [LeetCode 236] Lowest Common Ancestor of a Binary Tree
- LeetCode(236)Lowest Common Ancestor of a Binary Tree
- leetcode 236: Lowest Common Ancestor of a Binary Tree
- LeetCode 236: Lowest Common Ancestor of a Binary Tree
- 【LEETCODE】236-Lowest Common Ancestor of a Binary Tree
- LeetCode 236 Lowest Common Ancestor of a Binary Tree
- 【LeetCode-236】Lowest Common Ancestor of a Binary Tree
- leetcode 236Lowest Common Ancestor of a Binary Tree [python]
- Linux0.11内核--系统中断处理程序int 0x80实现原理
- jQuery 表单验证插件jQuery Validation Engine用法详解
- java线程Demo
- 心灵鸡汤之20160406
- MVVM简介
- 【LeetCode-236】Lowest Common Ancestor of a Binary Tree
- 三星s5pv210平台
- 列一些优化习惯(常更新)
- python编程基础-数据类型和函数
- kaggle——Influencers in Social Networks
- ios进程间通信问题之一--进程间通信 (OSX/iOS)
- 控制器Controller
- 浅析内存
- ios进程间通信问题之二----XPC