Skip to content

Commit 4210a48

Browse files
authored
Merge pull request #1035 from limlimjo/main
[jj7779607] Week11
2 parents 13ba8ba + ac76450 commit 4210a48

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)