【力扣】104. 二叉树的最大深度

104. 二叉树的最大深度

在这里插入图片描述

var maxDepth = function(root){
    if(!root) return 0;
    const stack = [root];
    let num = 0;
    while(stack.length){
        let len = stack.length;
        num++;
        while(len--){
            const o =stack.shift();
            o.left && stack.push(o.left);
            o.right && stack.push(o.right);
        }
    }
    return num;
}

猜你喜欢

转载自blog.csdn.net/weixin_44806635/article/details/131748191
今日推荐