559. N叉树的最大深度
狐七 leetCode树
/**
* // Definition for a Node.
* function Node(val,children) {
* this.val = val;
* this.children = children;
* };
*/
/**
* @param {Node|null} root
* @return {number}
*/
var maxDepth = function(root) {
if (root === null) return 0
let max = 0
root.children.forEach(val => {
max = Math.max(maxDepth(val), max)
})
return max+1
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20