Skip to content

Commit b7d136f

Browse files
committed
Time: 74 ms (56.25%), Space: 44.6 MB (63.62%) - LeetHub
1 parent 8a99c63 commit b7d136f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
15+
const dp = (node,depth)=>{
16+
if(!node) return depth
17+
18+
let l = depth,r =depth
19+
l = dp(node.left,depth + 1)
20+
r = dp(node.right,depth+ 1)
21+
22+
return Math.max(l,r)
23+
}
24+
const depth = dp(root,0)
25+
return depth
26+
};

0 commit comments

Comments
 (0)