Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5f251a7

Browse files
committed
增加Nom64
1 parent 387ca27 commit 5f251a7

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tree/Nom68.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package tree;
2+
3+
/**
4+
* @author tujietg
5+
* @date 5/30/20 11:05 AM
6+
*/
7+
public class Nom68 {
8+
9+
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
10+
if (root == null || root == p || root == q) {
11+
return root;
12+
}
13+
TreeNode leftNode = lowestCommonAncestor(root.left, p, q);
14+
TreeNode rightNode = lowestCommonAncestor(root.right, p, q);
15+
if (leftNode == null) {
16+
return rightNode;
17+
}
18+
if (rightNode == null) {
19+
return leftNode;
20+
}
21+
return root;
22+
}
23+
24+
}

tree/TreeNode.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tree;
2+
3+
/**
4+
* @author tujietg
5+
* @date 5/30/20 11:06 AM
6+
*/
7+
public class TreeNode {
8+
9+
int val;
10+
TreeNode left;
11+
TreeNode right;
12+
13+
TreeNode(int x) {
14+
val = x;
15+
}
16+
}

0 commit comments

Comments
 (0)