235. Lowest Common Ancestor of a Binary Search Tree
# Easy, DFS
node 1 and node 2.
From root to bottom, if node 1 is in left subtree and node 2 is in right subtree, root is their common ancestor. If both of them are in left or right subtree, continue searching the lowest common ancestor.
Key: 等同于找到这两个点的第一个分叉处。
stop condition is a little hard to think.
Last updated
Was this helpful?