LeetCode 513. 找树左下角的值 java题解

https://leetcode.cn/problems/find-bottom-left-tree-value/description/

java 复制代码
class Solution {
    int res=0;//初始值无所谓
    int max_depth=0;
    public int findBottomLeftValue(TreeNode root) {
        find(root,0);//
        return res;
    }
    public void find(TreeNode root,int depth){
        if(root==null) return;
        depth++;
        if(depth>max_depth){
            max_depth=depth;
            res=root.val;
        }
        find(root.left,depth);
        find(root.right,depth);
    }
}
/*
左中右,遍历节点。遍历过程中记录深度。
如果他的深度>max_depth,更新为结果。
*/
相关推荐
小毛驴85013 分钟前
Linux 后台启动java jar 程序 nohup java -jar
java·linux·jar
DKPT1 小时前
Java桥接模式实现方式与测试方法
java·笔记·学习·设计模式·桥接模式
好奇的菜鸟2 小时前
如何在IntelliJ IDEA中设置数据库连接全局共享
java·数据库·intellij-idea
大千AI助手3 小时前
DTW模版匹配:弹性对齐的时间序列相似度度量算法
人工智能·算法·机器学习·数据挖掘·模版匹配·dtw模版匹配
DuelCode3 小时前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis
优创学社23 小时前
基于springboot的社区生鲜团购系统
java·spring boot·后端
幽络源小助理3 小时前
SpringBoot基于Mysql的商业辅助决策系统设计与实现
java·vue.js·spring boot·后端·mysql·spring
猴哥源码3 小时前
基于Java+springboot 的车险理赔信息管理系统
java·spring boot
YuTaoShao4 小时前
【LeetCode 热题 100】48. 旋转图像——转置+水平翻转
java·算法·leetcode·职场和发展