File tree Expand file tree Collapse file tree 1 file changed +0
-19
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +0
-19
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
- * 236. Lowest Common Ancestor of a Binary Tree
7
- *
8
- * Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
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
11
- * that has both v and w as descendants (where we allow a node to be a descendant of itself).”
12
-
13
- _______3______
14
- / \
15
- ___5__ ___1__
16
- / \ / \
17
- 6 _2 0 8
18
- / \
19
- 7 4
20
-
21
- For example, the lowest common ancestor (LCA) of nodes 5 and 1 is 3.
22
- Another example is LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.*/
23
-
24
5
public class _236 {
25
6
public static class Solution1 {
26
7
You can’t perform that action at this time.
0 commit comments