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 f1cdd1e commit 80dd434Copy full SHA for 80dd434
โmaximum-depth-of-binary-tree/jinvicky.javaโ
@@ -0,0 +1,11 @@
1
+class Solution {
2
+ // ์ต๋ ๊น์ด๋ฅผ ํ์ํ๋ ๊ฒ์ด๋ฏ๋ก BFS๋ณด๋ค DFS๊ฐ ๋ ์ ์ ํฉ๋๋ค.
3
+ // ๋งค ๋ ธ๋์ left, right์ ์ฌ๊ท๋ก ํธ์ถํด์ ์ต๋ ๊น์ด๋ฅผ ๋ฐํํฉ๋๋ค. ์ฌ๊ท ํจ์ ํ์.
4
+ public int maxDepth(TreeNode root) {
5
+ // ์ฌ๊ท ์ข ๋ฃ ์กฐ๊ฑด == left ํน์ right๊ฐ null์ผ ๋, root ์์ฒด๊ฐ ๋์ด๋ผ๋ฉด?
6
+ if (root == null) return 0;
7
+
8
+ // ๋์ ์ ์ํด์ 1+๋ฅผ ํ๊ณ , Math.max()๋ก ์ต๋๊ฐ์ ๊ตฌํฉ๋๋ค.
9
+ return 1+ Math.max(maxDepth(root.left), maxDepth(root.right));
10
+ }
11
+}
0 commit comments