Skip to content

Commit da53272

Browse files
committed
[week3] solve 104. Maximum Depth of Binary Tree
1 parent 439f8c5 commit da53272

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* TC: O(N)
3+
* SC: O(N)
4+
*/
5+
class Solution {
6+
7+
public int maxDepth(TreeNode root) {
8+
return findMax(root, 0);
9+
}
10+
11+
public int findMax(TreeNode node, int depth) {
12+
if (node == null) {
13+
return depth;
14+
}
15+
return Math.max(findMax(node.left, depth + 1), findMax(node.right, depth + 1));
16+
}
17+
}

0 commit comments

Comments
 (0)