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

513. 找树左下角的值
js 复制代码
/**
 * 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. 找树左下角的值

相关推荐
iFlyCai13 小时前
数据结构与算法之希尔排序
数据结构·算法·排序算法
Nontee13 小时前
Leetcode Top100答案和解释 -- Python版本(矩阵)
python·leetcode·矩阵
lcreek13 小时前
LeetCode2208. 将数组和减半的最少操作次数、LeetCode2406.将区间分为最少组数
python·算法
shehuiyuelaiyuehao13 小时前
算法1,移动零
数据结构·算法·排序算法
shehuiyuelaiyuehao13 小时前
算法2,复写零
数据结构·算法
像污秽一样13 小时前
算法设计与分析-算法效率分析基础-习题1.1
c语言·数据结构·c++·算法
abant214 小时前
leetcode 739 单调栈模板题
算法·leetcode·职场和发展
宝贝儿好19 小时前
【强化学习实战】第十一章:Gymnasium库的介绍和使用(1)、出租车游戏代码详解(Sarsa & Q learning)
人工智能·python·深度学习·算法·游戏·机器学习
weixin_458872611 天前
东华复试OJ二刷复盘2
算法
Charlie_lll1 天前
力扣解题-637. 二叉树的层平均值
算法·leetcode