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

相关推荐
长安er9 小时前
LeetCode215/347/295 堆相关理论与题目
java·数据结构·算法·leetcode·
元亓亓亓9 小时前
LeetCode热题100--62. 不同路径--中等
算法·leetcode·职场和发展
小白菜又菜9 小时前
Leetcode 1925. Count Square Sum Triples
算法·leetcode
登山人在路上10 小时前
Nginx三种会话保持算法对比
算法·哈希算法·散列表
写代码的小球10 小时前
C++计算器(学生版)
c++·算法
AI科技星11 小时前
张祥前统一场论宇宙大统一方程的求导验证
服务器·人工智能·科技·线性代数·算法·生活
Fuly102411 小时前
大模型剪枝(Pruning)技术简介
算法·机器学习·剪枝
Xの哲學11 小时前
Linux网卡注册流程深度解析: 从硬件探测到网络栈
linux·服务器·网络·算法·边缘计算
bubiyoushang88811 小时前
二维地质模型的表面重力值和重力异常计算
算法
仙俊红12 小时前
LeetCode322零钱兑换
算法