Skip to content

Commit 934a0af

Browse files
committed
Maximum Depth of Binary Tree solution
1 parent 76b63ad commit 934a0af

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class Solution {
2+
public int maxDepth(TreeNode root) {
3+
if (root == null) return 0;
4+
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
5+
}
6+
}
7+
8+
class TreeNode {
9+
int val;
10+
TreeNode left;
11+
TreeNode right;
12+
13+
TreeNode() {
14+
}
15+
16+
TreeNode(int val) {
17+
this.val = val;
18+
}
19+
20+
TreeNode(int val, TreeNode left, TreeNode right) {
21+
this.val = val;
22+
this.left = left;
23+
this.right = right;
24+
}
25+
}

0 commit comments

Comments
 (0)