Skip to content

Commit bcb0e8e

Browse files
author
Li Li
committed
add code of 235
1 parent 2187ccf commit bcb0e8e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Solution {
2+
public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
3+
if (root == null) return null;
4+
if (root.val == p.val || root.val == q.val) return root;
5+
TreeNode left = LowestCommonAncestor(root.left, p, q);
6+
TreeNode right = LowestCommonAncestor(root.right, p, q);
7+
if (left != null && right != null) return root;
8+
else if (left == null) return right;
9+
else return left;
10+
}
11+
}

0 commit comments

Comments
 (0)