当前位置:网站首页>LeetCode 513. Find the value in the lower left corner of the tree
LeetCode 513. Find the value in the lower left corner of the tree
2022-07-03 09:01:00 【Sasakihaise_】
513. Find the value in the lower left corner of the tree

【 Level traversal 】 Just find the value at the bottom of the last layer
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
int bfs(TreeNode node){
Queue<TreeNode> queue = new LinkedList();
queue.offer(node);
int ret = node.val;
while(!queue.isEmpty()){
int n = queue.size();
for(var i = 0; i < n; i++){
TreeNode top = queue.poll();
if(i == 0) ret = top.val;
if(top.left != null) queue.offer(top.left);
if(top.right != null) queue.offer(top.right);
}
}
return ret;
}
public int findBottomLeftValue(TreeNode root) {
return bfs(root);
}
}
边栏推荐
- Low code momentum, this information management system development artifact, you deserve it!
- LeetCode 513. 找树左下角的值
- [concurrent programming] explicit lock and AQS
- Character pyramid
- AcWing 785. 快速排序(模板)
- excel一小时不如JNPF表单3分钟,这样做报表,领导都得点赞!
- I made mistakes that junior programmers all over the world would make, and I also made mistakes that I shouldn't have made
- On a un nom en commun, maître XX.
- 数位统计DP AcWing 338. 计数问题
- php public private protected
猜你喜欢

低代码前景可期,JNPF灵活易用,用智能定义新型办公模式

Tree DP acwing 285 A dance without a boss

Dom4j遍历和更新XML

PIC16F648A-E/SS PIC16 8位 微控制器,7KB(4Kx14)

Parameters of convolutional neural network

AcWing 785. 快速排序(模板)

状态压缩DP AcWing 91. 最短Hamilton路径

Allocation exception Servlet

Discussion on enterprise informatization construction

网络安全必会的基础知识
随机推荐
剑指 Offer II 029. 排序的循环链表
数位统计DP AcWing 338. 计数问题
LeetCode 513. 找树左下角的值
教育信息化步入2.0,看看JNPF如何帮助教师减负,提高效率?
22-05-26 西安 面试题(01)准备
Too many open files solution
使用dlv分析golang进程cpu占用高问题
MySQL index types B-tree and hash
Using DLV to analyze the high CPU consumption of golang process
20220630 learning clock in
[concurrent programming] concurrent security
[rust note] 10 operator overloading
樹形DP AcWing 285. 沒有上司的舞會
常见渗透测试靶场
注解简化配置与启动时加载
22-05-26 Xi'an interview question (01) preparation
[rust notes] 09- special types and generics
LeetCode 871. 最低加油次数
高斯消元 AcWing 883. 高斯消元解线性方程组
[concurrent programming] atomic operation CAS