We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents ddbf2dc + 3edf1fb commit cf5691aCopy full SHA for cf5691a
โmaximum-depth-of-binary-tree/anniemon.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * ์๊ฐ ๋ณต์ก๋:
3
+ * ๋ ธ๋์ ๊ฐฏ์๋งํผ ํ์ํ๋ฏ๋ก, O(n)
4
+ * ๊ณต๊ฐ ๋ณต์ก๋:
5
+ * ์ฌ๊ท ํธ์ถ ์คํ์ ํฌ๊ธฐ๋ ํธ๋ฆฌ๊ฐ ํ์ชฝ์ผ๋ก ์น์ฐ์น ๊ฒฝ์ฐ O(n)๋ก ์ต์ ์ด ๋๊ณ ,
6
+ * ๊ท ํ ์กํ ํธ๋ฆฌ์ ๊ฒฝ์ฐ O(log n)์ด๋ค.
7
+ */
8
9
+ * Definition for a binary tree node.
10
+ * function TreeNode(val, left, right) {
11
+ * this.val = (val===undefined ? 0 : val)
12
+ * this.left = (left===undefined ? null : left)
13
+ * this.right = (right===undefined ? null : right)
14
+ * }
15
16
17
+ * @param {TreeNode} root
18
+ * @return {number}
19
20
+var maxDepth = function(root) {
21
+ const dfs = (node) => {
22
+ if(!node) return 0;
23
+ return Math.max(dfs(node.left) + 1, dfs(node.right) + 1);
24
+ }
25
+ return dfs(root);
26
+};
0 commit comments