数据结构与算法之 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 = rootwhile(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. 找树左下角的值