Skip to content

Commit b71c7e9

Browse files
authored
Update Readme.md
1 parent 61572cf commit b71c7e9

File tree

1 file changed

+2
-2
lines changed
  • Tree/236.Lowest-Common-Ancestor-of-a-Binary-Tree

1 file changed

+2
-2
lines changed

Tree/236.Lowest-Common-Ancestor-of-a-Binary-Tree/Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ DFS函数会一路向下层搜索直到发现节点p,然后在返回的过程
3333
3434
1.如果node是NULL或者p或者q,那么我们就返回node,表示我们定位到了p/q。
3535
36-
2.分别递归调用```left=lowestCommonAncestor(node->left,p,q); right=lowestCommonAncestor(node->right,p,q)```.如果left和right都非空,那么说明node一定就是LCA。如果left非空而right为空,说明我们定位到了p,或者说是p,q的LCA,不管如何,都返回left。同理,如果right非空而left为空,说明我们定位到了q或者是pq的LCA。两者都为空,那么就自然返回空。
36+
2.分别递归调用```left=lowestCommonAncestor(node->left,p,q); right=lowestCommonAncestor(node->right,p,q)```.如果left和right都非空,那么必然说明一个分支含有p,另一个分支含有q,故node一定就是LCA。如果left非空而right为空,说明我们在左边定位到了p或者q或者是p,q的LCA,不管如何,都返回left。同理,如果right非空而left为空,说明我们在右边定位到了p或q或者是pq的LCA。如果两者都为空,那么就自然返回空。
3737
3838
39-
[Leetcode Link](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree)
39+
[Leetcode Link](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree)

0 commit comments

Comments
 (0)