Skip to content

Commit 2942484

Browse files
authored
Typing
1 parent d65fca9 commit 2942484

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

2018.12.07-leetcode104/Typing.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
public class Main104 {
2+
public static void main(String[] args){
3+
Main104 main = new Main104();
4+
main.test();
5+
}
6+
7+
public void test(){
8+
TreeNode root = new TreeNode(3);
9+
root.left = new TreeNode(9);
10+
root.right = new TreeNode(20);
11+
root.right.left = new TreeNode(15);
12+
root.right.right = new TreeNode(7);
13+
System.out.println(maxDepth(root));
14+
}
15+
16+
public int maxDepth(TreeNode root) {
17+
int leftDep,rightDep,max;
18+
if (root!=null){
19+
leftDep = maxDepth(root.left);
20+
rightDep = maxDepth(root.right);
21+
max = leftDep>rightDep?leftDep:rightDep;
22+
return max+1;
23+
}
24+
return 0;
25+
}
26+
27+
private class TreeNode{
28+
int val;
29+
TreeNode left;
30+
TreeNode right;
31+
TreeNode(int x){
32+
val = x;
33+
}
34+
}
35+
36+
}

0 commit comments

Comments
 (0)