leetcode -- Lowest Common Ancestor of a Binary Search Tree -- 简单递归,掌握思想
来源:互联网 发布:宁波用友软件代理商 编辑:程序博客网 时间:2024/06/03 19:01
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/
ref: http://bookshadow.com/weblog/2015/07/11/leetcode-lowest-common-ancestor-binary-search-tree/
class Solution(object): def lowestCommonAncestor(self, root, p, q): """ :type root: TreeNode :type p: TreeNode :type q: TreeNode :rtype: TreeNode """ if (q.val - root.val) * (p.val - root.val) <= 0: return root.val elif q.val > root.val : return self.lowestCommonAncestor(root.right, p, q) else: return self.lowestCommonAncestor(root.left, p, q)
0 0
- leetcode -- 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: 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】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] Lowest Common Ancestor of a Binary Search Tree
- LeetCode Lowest Common Ancestor of a Binary Search Tree
- leetCode(38):Lowest Common Ancestor of a Binary Search 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 Search Tree
- leetcode[235]:Lowest Common Ancestor of a Binary Search Tree
- Lowest Common Ancestor of a Binary Search Tree-leetcode
- 【leetcode】Lowest Common Ancestor of a Binary Search Tree
- [Numerical_analysis]the_third_project
- 【读书笔记】统计学:从数据到结论 第十章
- MQ测试:发出第一条MQ消息
- 【Web安全与防御】简析Sql注入与防御措施
- Fragment切换百度地图,黑屏
- leetcode -- Lowest Common Ancestor of a Binary Search Tree -- 简单递归,掌握思想
- MySQL数据类型和常用字段属性总结
- 【springmvc+mybatis项目实战】杰信商贸-31.出口报运业务-购销合同查询与上报
- Android学习之路-fragment之三
- ecstore-隐藏版权信息
- Android线程之间的通讯机制Handler
- hdu2150 Pipe (判断线段是否相交)
- android学习笔记-接口回调简析
- Web前端开发之定义全局的上下文路径