leetcode 236. Lowest Common Ancestor of a Binary Tree
2017-08-26 11:40
323 查看
class Solution(object): def lowestCommonAncestor(self, root, p, q): """ :type root: TreeNode :type p: TreeNode :type q: TreeNode :rtype: TreeNode """ if root in (p,q,None): return root left_res = self.lowestCommonAncestor(root.left,p,q) right_res = self.lowestCommonAncestor(root.right,p,q) if left_res and right_res: return root else: return left_res if left_res else right_res
相关文章推荐
- 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(Medium)解题报告
- leetcode 236. Lowest Common Ancestor of a Binary Tree 最近公告祖先LCA + 二叉树 + 深度优先遍历DFS
- 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 -- JavaScript 代码
- 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