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 b5c7975 commit f806b49Copy full SHA for f806b49
maximum-depth-of-binary-tree/grapefruitgreentealoe.js
@@ -0,0 +1,22 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val, left, right) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.left = (left===undefined ? null : left)
6
+ * this.right = (right===undefined ? null : right)
7
+ * }
8
+ */
9
10
+ * @param {TreeNode} root
11
+ * @return {number}
12
13
+var maxDepth = function (root) {
14
+ if (!root) return 0;
15
+
16
+ // 왼쪽과 오른쪽 서브트리의 최대 깊이를 구한다.
17
+ const leftDepth = maxDepth(root.left);
18
+ const rightDepth = maxDepth(root.right);
19
20
+ // 현재 노드의 깊이는 왼쪽과 오른쪽 깊이 중 큰 값에 1을 더한 값이다.
21
+ return Math.max(leftDepth, rightDepth) + 1;
22
+};
0 commit comments