原文:Lowest Common Ancestor of Two Nodes in a Binary Tree

Reference: http: blog.csdn.net v july v article details http: leetcode.com lowest common ancestor of a binary tree part ii.html Is the tree a BST or not BST的话,我们就能按照BST的定义思考了。当前遍历的node如果比我们要找的两个点都大,说 ...

2014-12-04 08:16 0 2424 推荐指数:

查看详情

236. Lowest Common Ancestor of a Binary Tree

题目: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia ...

Sun Nov 29 07:56:00 CST 2015 0 2115
FB面经 Prepare: LCA of Deepest Nodes in Binary Tree

Recursion: 返回的时候返回lca和depth,每个node如果有大于一个子节点的depth相同就返回这个node,如果有一个子节点depth更深就返回个子节点lca,这个o(n)就可以了 Iteration: tree的recursion换成iteration处理 ...

Wed Mar 15 08:38:00 CST 2017 0 1300
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM