当前位置:网站首页>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);
}
}
边栏推荐
- In the digital transformation, what problems will occur in enterprise equipment management? Jnpf may be the "optimal solution"
- Dom4j traverses and updates XML
- php public private protected
- The method for win10 system to enter the control panel is as follows:
- PHP uses foreach to get a value in a two-dimensional associative array (with instances)
- Find the combination number acwing 886 Find the combination number II
- Discussion on enterprise informatization construction
- Escape from heaven and forget what he suffered. In ancient times, it was called the punishment of escape from heaven. Article collection
- Debug debugging - Visual Studio 2022
- Format - C language project sub file
猜你喜欢

Arbre DP acwing 285. Un bal sans patron.

TP5 multi condition sorting

LeetCode 75. 颜色分类

Complex character + number pyramid

LeetCode 1089. 复写零

Vscode connect to remote server

Education informatization has stepped into 2.0. How can jnpf help teachers reduce their burden and improve efficiency?

状态压缩DP AcWing 291. 蒙德里安的梦想

LeetCode 241. 为运算表达式设计优先级

传统办公模式的“助推器”,搭建OA办公系统,原来就这么简单!
随机推荐
低代码起势,这款信息管理系统开发神器,你值得拥有!
传统办公模式的“助推器”,搭建OA办公系统,原来就这么简单!
Concurrent programming (VI) ABA problems and solutions under CAS
网络安全必会的基础知识
22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
The method of replacing the newline character '\n' of a file with a space in the shell
TP5 multi condition sorting
Solution of 300ms delay of mobile phone
Wonderful review | i/o extended 2022 activity dry goods sharing
AcWing 788. 逆序对的数量
Markdown learning
常见渗透测试靶场
Convert video to GIF
Deeply understand the underlying data structure of MySQL index
LeetCode 515. 在每个树行中找最大值
[rust notes] 13 iterator (Part 1)
On the setting of global variable position in C language
LeetCode 1089. 复写零
LeetCode 508. 出现次数最多的子树元素和
Slice and index of array with data type