diff --git a/maximum-depth-of-binary-tree/yeonjukim164.java b/maximum-depth-of-binary-tree/yeonjukim164.java new file mode 100644 index 0000000000..a7078c0104 --- /dev/null +++ b/maximum-depth-of-binary-tree/yeonjukim164.java @@ -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; + } +}