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 687e199 commit ac76450Copy full SHA for ac76450
maximum-depth-of-binary-tree/limlimjo.js
@@ -0,0 +1,23 @@
1
+// 시간 복잡도: O(n)
2
+// 공간 복잡도: O(n)
3
+
4
+/**
5
+ * Definition for a binary tree node.
6
+ * function TreeNode(val, left, right) {
7
+ * this.val = (val===undefined ? 0 : val)
8
+ * this.left = (left===undefined ? null : left)
9
+ * this.right = (right===undefined ? null : right)
10
+ * }
11
+ */
12
13
+ * @param {TreeNode} root
14
+ * @return {number}
15
16
+var maxDepth = function (root) {
17
+ if (!root) return 0;
18
19
+ let leftDepth = maxDepth(root.left);
20
+ let rightDepth = maxDepth(root.right);
21
22
+ return Math.max(leftDepth, rightDepth) + 1;
23
+};
0 commit comments