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 9cb7c0b commit 86be455Copy full SHA for 86be455
โmaximum-depth-of-binary-tree/YuuuuuuYu.javaโ
@@ -0,0 +1,20 @@
1
+/**
2
+ * Runtime: 0ms
3
+ * Time Complexity: O(n)
4
+ *
5
+ * Memory: 44.28MB
6
+ * Space Complexity: O(h)
7
+ * - h: ํธ๋ฆฌ์ ๋์ด or ์ต๋ ๊น์ด
8
9
+ * Approach: ์ฌ๊ท๋ฅผ ์ด์ฉํ DFS ์ ๊ทผ๋ฒ
10
+ * - ๋ฃจํธ๋ถํฐ ์์ํ์ฌ ์ฌ๊ท๊ฐ ์์ํ ๋๋ง๋ค 1๋ก ๊ณ์ฐ
11
+ * - ํธ๋ฆฌ์ ๋์ ๋๋ฌํ๋ฉด 0์ ๋ฆฌํดํ์ฌ ์ฐจ๋ก๋๋ก ๋จ์ ๊น์ด๋ฅผ ๊ณ์ฐ
12
+ */
13
+class Solution {
14
+ public int maxDepth(TreeNode root) {
15
+ if (root == null)
16
+ return 0;
17
+
18
+ return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
19
+ }
20
+}
0 commit comments