Skip to content

Commit 8c03da8

Browse files
committed
Maximum Depth of Binary Tree 문제 풀이
1 parent 50c7acb commit 8c03da8

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int maxDepth(TreeNode root) {
3+
// Base Case: 노드가 없으면 깊이는 0
4+
if (root == null) {
5+
return 0;
6+
}
7+
8+
// Recursive Step: 왼쪽 깊이와 오른쪽 깊이 중 더 깊은 곳 + 1 (내 키)
9+
int leftDepth = maxDepth(root.left);
10+
int rightDepth = maxDepth(root.right);
11+
12+
return Math.max(leftDepth, rightDepth) + 1;
13+
}
14+
}

0 commit comments

Comments
 (0)