File tree Expand file tree Collapse file tree 1 file changed +0
-20
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +0
-20
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import com .fishercoder .common .classes .TreeNode ;
4
4
5
- /**
6
- * 235. Lowest Common Ancestor of a Binary Search Tree
7
- *
8
- * Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.
9
- * According to the definition of LCA on Wikipedia:
10
- * “The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants
11
- * (where we allow a node to be a descendant of itself).”
12
-
13
- _______6______
14
- / \
15
- ___2__ ___8__
16
- / \ / \
17
- 0 4 7 9
18
- / \
19
- 3 5
20
-
21
- For example, the lowest common ancestor (LCA) of nodes 2 and 8 is 6.
22
- Another example is LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition.
23
-
24
- */
25
5
public class _235 {
26
6
27
7
public static class Solution1 {
You can’t perform that action at this time.
0 commit comments