Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions maximum-depth-of-binary-tree/yeonjukim164.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public int maxDepth(TreeNode root) {
// Base Case: 노드가 없으면 깊이는 0
if (root == null) {
return 0;
}

// Recursive Step: 왼쪽 깊이와 오른쪽 깊이 중 더 깊은 곳 + 1 (내 키)
int leftDepth = maxDepth(root.left);
int rightDepth = maxDepth(root.right);

return Math.max(leftDepth, rightDepth) + 1;
}
}