We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3d52010 + 8c03da8 commit d16b627Copy full SHA for d16b627
1 file changed
maximum-depth-of-binary-tree/yeonjukim164.java
@@ -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