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.
1 parent 409c862 commit 1e321a7Copy full SHA for 1e321a7
โmaximum-depth-of-binary-tree/hyunjung-choi.ktโ
@@ -0,0 +1,20 @@
1
+// ์๊ฐ ๋ณต์ก๋: O(n)
2
+// - n: ํธ๋ฆฌ์ ๋ ธ๋ ๊ฐ์
3
+// - ๊ฐ ๋ ธ๋๋ฅผ ์ ํํ ํ ๋ฒ์ฉ ๋ฐฉ๋ฌธํ๋ฏ๋ก O(n)
4
+//
5
+// ๊ณต๊ฐ ๋ณต์ก๋: O(h)
6
+// - h: ํธ๋ฆฌ์ ๋์ด
7
+// - ์ฌ๊ท ํธ์ถ ์คํ์ ์ต๋ h๊ฐ์ ํจ์ ํธ์ถ์ด ์์
8
+// - ์ต์ ์ ๊ฒฝ์ฐ(ํธํฅ ํธ๋ฆฌ) h = n ์ด๋ฏ๋ก O(n),
9
+// ์ต์ ์ ๊ฒฝ์ฐ(๊ท ํ ํธ๋ฆฌ) h = log n ์ด๋ฏ๋ก O(log n)
10
+
11
+class Solution {
12
+ fun maxDepth(root: TreeNode?): Int {
13
+ if (root == null) return 0
14
15
+ val leftDepth = maxDepth(root.left)
16
+ val rightDepth = maxDepth(root.right)
17
18
+ return maxOf(leftDepth, rightDepth) + 1
19
+ }
20
+}
0 commit comments