当前位置:网站首页>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);
}
}
边栏推荐
- MySQL three logs
- PHP uses foreach to get a value in a two-dimensional associative array (with instances)
- Deep parsing JVM memory model
- [rust notes] 08 enumeration and mode
- [rust notes] 02 ownership
- Deep parsing (picture and text) JVM garbage collector (II)
- Monotonic stack -84 The largest rectangle in the histogram
- [concurrent programming] explicit lock and AQS
- Try to reprint an article about CSDN reprint
- LeetCode 508. 出现次数最多的子树元素和
猜你喜欢
Phpstudy 80 port occupied W10 system
教育信息化步入2.0,看看JNPF如何帮助教师减负,提高效率?
22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
Format - C language project sub file
低代码前景可期,JNPF灵活易用,用智能定义新型办公模式
Discussion on enterprise informatization construction
too many open files解决方案
状态压缩DP AcWing 291. 蒙德里安的梦想
22-06-28 Xi'an redis (02) persistence mechanism, entry, transaction control, master-slave replication mechanism
Arbre DP acwing 285. Un bal sans patron.
随机推荐
DOM 渲染系统(render mount patch)响应式系统
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q
Deep parsing JVM memory model
教育信息化步入2.0,看看JNPF如何帮助教师减负,提高效率?
干货!零售业智能化管理会遇到哪些问题?看懂这篇文章就够了
Really explain the five data structures of redis
Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
How to delete CSDN after sending a wrong blog? How to operate quickly
Too many open files solution
I made mistakes that junior programmers all over the world would make, and I also made mistakes that I shouldn't have made
PHP function date (), y-m-d h:i:s in English case
[concurrent programming] explicit lock and AQS
Find the combination number acwing 885 Find the combination number I
记忆化搜索 AcWing 901. 滑雪
数位统计DP AcWing 338. 计数问题
注解简化配置与启动时加载
MySQL three logs
excel一小时不如JNPF表单3分钟,这样做报表,领导都得点赞!
Markdown learning
Divide candy (circular queue)