当前位置:网站首页>【日常训练】513. 找树左下角的值
【日常训练】513. 找树左下角的值
2022-06-23 05:58:00 【Puppet__】
题目
给定一个二叉树的 根节点 root,请找出该二叉树的 最底层 最左边 节点的值。
假设二叉树中至少有一个节点。
示例 1:
输入: root = [2,1,3]
输出: 1
示例 2:
输入: [1,2,3,4,null,5,6,null,null,7]
输出: 7
提示:
二叉树的节点个数的范围是 [1,104]
-231 <= Node.val <= 231 - 1
代码
package dayLeetCode;
import java.util.TreeMap;
public class dayleetcode513 {
// 记录结果
int ansNodeVal = 0;
// 记录当前层
int curHeight = 0;
// dfs
public int findBottomLeftValue(TreeNode root) {
dfs(root, 0);
return ansNodeVal;
}
void dfs(TreeNode node, int height){
if (node == null){
return;
}
height++;
dfs(node.left, height);
dfs(node.right, height);
// 如果比当前层深,就更新
if (height > curHeight){
curHeight = height;
ansNodeVal = node.val;
}
}
}
边栏推荐
- Gridsearchcv (grid search), a model parameter adjuster in sklearn
- Business logic design of physical warehouse and virtual warehouse in middle inventory
- [QT] basic learning notes
- 【毕业季·进击的技术er】自己的选择,跪着也要走
- /bin/sh no such file or directory问题
- Programmers' real ideas | daily anecdotes
- Concepts and differences of DQL, DML, DDL and DCL
- Children's programming for comprehensively cultivating students' mental thinking
- 利用adb 调试设备串口信息的一个小方法
- 疫情下的传媒产业,小程序生态驱动数字化转型探索
猜你喜欢

mysql 基础查询

Linux Installation mysql8.0.25

Cloud box is deeply convinced to create a smart dual-mode teaching resource sharing platform for Nanjing No. 1 middle school

idea的去除转义的复制粘贴

Chrome删除重复书签

xml dtd 记录

haas506 2.0开发教程-高级组件库-modem.sms(仅支持2.2以上版本)

leetcode - 572. A subtree of another tree

Data indicators and data analysis models that designers need to understand

leetcode - 572. 另一棵树的子树
随机推荐
xml schem 记录
js中if逻辑过多,常见优化
回调函数详解
疫情下的传媒产业,小程序生态驱动数字化转型探索
js 动态创建a href 循环下载文件只能下载10个或者固定数目的问题
Phpstudy set 301 redirection
聚焦智慧城市,华为携手中科星图共同开拓数字化新蓝海
数据在内存中的存储方式(C语言)
Wechat applet - Global Monitoring of certain attribute changes of GlobalData, such as monitoring of network state switching
Add IPAD control function into shairplay
从 WAN 到 SD-WAN 边缘设备的网络架构
C# 获取DPI和真实分辨率的方式(可以解决一直是96的问题)
Summary of qvariant use in QT
网页制作存在的一些难点
【系统】右键桌面图标,转圈后,资源管理器就崩溃,桌面就重新刷新
Network architecture from Wan to sd-wan edge devices
项目_过滤器Filter解决中文乱码
leetcode - 572. A subtree of another tree
将TensorFlow1.x改写为pytorch
Media industry under the epidemic situation, small program ecology driven digital transformation exploration