原文: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