当前位置:网站首页>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;
}
}
边栏推荐
- Communication mechanism cases
- Unityshader depth texture (understanding and problems encountered)
- 5g's past and present life -- a brief introduction to the development of mobile communication
- Dynamic programming for solving problems (2)
- wireshark图形界面抓包
- Wireshark packet modification -- adding or modifying message fields (2)
- Ram of IP core
- Basic concepts of software testing
- Brief introduction to unity menu interface
- Reading and writing of C # file
猜你喜欢

机器人导航

IP核之RAM
![[Arduino] reborn Arduino monk (1)](/img/ce/67118ebd430a0ff3ef98ec8524ee4a.jpg)
[Arduino] reborn Arduino monk (1)

自动化部署项目

Pzk learns data types, binary conversion, input and output, operators, branch statements, ifelse of C language

ROS distributed communication

wireshark IP地址域名解析

Robot navigation implementation

内部类的相关知识

Unityshader depth texture (understanding and problems encountered)
随机推荐
Dynamic planning for solving problems (3)
The principle of hash table and the solution of hash conflict
Basic concepts of software testing
5G网络身份识别---详解5G-GUTI
切线空间以及TBN矩阵
Remote sensing image recognition misclassification under multi class recognition
力扣每日一题leetcode 513. 找树左下角的值
ROS话题名称设置
Tangent space and TBN matrix
Wireshark packet modification -- adding or modifying message fields (2)
Unity 引擎开始从 Mono 迁移到 .NET CoreCLR
自动追随跟踪
多线程的知识补充
shell script if嵌套for循环脚本
Dynamic planning for solving problems (4)
非真实感渲染(NPR)论文理解及其复现(Unity) - 《Stylized Highlights for Cartoon Rendering and Animation》
Li Kou 236. the nearest common ancestor of binary tree
Unity 菜单界面的简单介绍
Strategies for common locks in multithreading
Understand the pointer in a picture