Skip to content

Commit 7a7485c

Browse files
committed
Time: 0 ms (100.00%), Space: 43.9 MB (5.88%) - LeetHub
1 parent af600ae commit 7a7485c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode() {}
8+
* TreeNode(int val) { this.val = val; }
9+
* TreeNode(int val, TreeNode left, TreeNode right) {
10+
* this.val = val;
11+
* this.left = left;
12+
* this.right = right;
13+
* }
14+
* }
15+
*/
16+
class Solution {
17+
public int maxDepth(TreeNode root) {
18+
19+
if(root == null) return 0;
20+
21+
int left = maxDepth(root.left);
22+
int right = maxDepth(root.right);
23+
24+
return Math.max(left, right) + 1;
25+
26+
27+
}
28+
}

0 commit comments

Comments
 (0)