数据结构与算法之 leetcode 513. 找树左下角的值 (BFS) 广度优先

513. 找树左下角的值
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var findBottomLeftValue = function(root) {
    
    
    let q = [root]
    let node = root
    while(q.length){
    
    
         node = q.shift()
        if(node.right)
            q.push(node.right)
        if(node.left)
            q.push(node.left)
    }
    return node.val
};
执行用时分布
75ms
击败30.26%

消耗内存分布
57.21MB
击败73.68%
参考链接

513. 找树左下角的值

猜你喜欢

转载自blog.csdn.net/qq_25482087/article/details/139455920