Given the root and two nodes in a Binary Tree. Find the lowest common ancestor(LCA) of the two nodes.
The lowest common ancestor is the node with largest depth which is the ancestor of both nodes.
Notice
Assume two nodes are exist in tree.
Example
For the following binary tree:
4
/ \
3 7
/ \
5 6
LCA(3, 5) = 4
LCA(5, 6) = 7
LCA(6, 7) = 7
本文介绍了一种在二叉树中寻找两个指定节点的最低公共祖先(LCA)的方法。最低公共祖先是这两个节点共有的最深的祖先节点。文章通过示例展示了如何在给定的二叉树结构中找到不同节点对的最低公共祖先。

被折叠的 条评论
为什么被折叠?



