当前位置:网站首页>Li Kou daily question leetcode 513. find the value in the lower left corner of the tree
Li Kou daily question leetcode 513. find the value in the lower left corner of the tree
2022-07-27 06:21:00 【The last tripod】
leetcode 513. Find the value in the lower left corner of the tree 

Ideas Simple depth traversal , It combines the idea of post order traversal of binary tree . First, keep walking down , When traversing downward, first traverse left ( Ensure that the deepest value obtained is on the far left ), If you find that the traversal depth is greater than the existing depth, change the maximum depth to the current depth , Values are also modified .
class Solution {
int val;
int deep = -1;
public void dfs(TreeNode root,int depth){
if(root == null)return;
dfs(root.left,depth+1);// Traverse left
dfs(root.right,depth+1);// Traverse right
if(depth > deep){
// When the code runs here, all the child nodes of this node have been traversed , If you don't understand, you can look at the post order traversal of binary trees , The core is backtracking
deep = depth;// Modify depth
val = root.val;// Modified value
}
}
public int findBottomLeftValue(TreeNode root) {
dfs(root,0);
return val;
}
}
边栏推荐
- Wireshark packet modification -- adding or modifying message fields (2)
- Linear progression for face recognition
- SQL novice
- C thread lock
- ROS分布式通信
- 通信机制比较
- ROS distributed communication
- 非真实感渲染(NPR)论文理解及其复现(Unity) - 《Stylized Highlights for Cartoon Rendering and Animation》
- 机器人导航实现
- 5g network identity - detailed explanation of 5g Guti
猜你喜欢
随机推荐
通信机制比较
Unity practical tips (updating)
5g network identity - detailed explanation of 5g Guti
遥感影像识别-训练策略
Comparison of communication mechanisms
数据库的联合查询
机器人导航实现
Understand the pointer in a picture
非真实感渲染(NPR)论文理解及其复现(Unity) - 《Stylized Highlights for Cartoon Rendering and Animation》
Unityshader Gaussian blur
ULCL功能--5GC
yum获取rpm软件包的三种方法
导航相关消息
力扣题解 动态规划(2)
Ram of IP core
[Arduino] reborn Arduino monk (1)
UnityShader-深度纹理(理解以及遇到的问题)
自动追随跟踪
Shell script if nested for loop script
IP核之RAM








