Skip to content

559. N叉树的最大深度

leetCode-559. N叉树的最大深度

js
/**
 * // 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
};

MIT Licensed