当前位置:网站首页>Leetcode: binary tree 15 (find the value in the lower left corner of the tree)
Leetcode: binary tree 15 (find the value in the lower left corner of the tree)
2022-07-05 20:00:00 【Taotao can't learn English】
513. Find the value in the lower left corner of the tree
Given a binary tree , Find the leftmost value in the last row of the tree .
Example 1:
Example 2:
… Isn't it the first in the last line of sequence traversal
package com.programmercarl.tree;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
/** * @ClassName FindBottomLeftValue * @Descriotion TODO * @Author nitaotao * @Date 2022/7/5 11:26 * @Version 1.0 * https://leetcode.cn/problems/find-bottom-left-tree-value/ * 513. Find the value in the lower left corner of the tree **/
public class FindBottomLeftValue {
/** * Given a binary tree The root node root, Please find the of the binary tree At the bottom Leftmost The value of the node . * Suppose there is at least one node in the binary tree . * <p> * .. Isn't it the first in the last line of sequence traversal * @param root * @return */
public int findBottomLeftValue(TreeNode root) {
if (root.left == null && root.right == null) {
return root.val;
}
int result = root.val;
Deque<TreeNode> deque = new ArrayDeque();
deque.offer(root);
while (!deque.isEmpty()) {
// The beginning of each floor
result = deque.peek().val;
int size = deque.size();
while (size > 0) {
root = deque.pop();
if (root.left != null) {
deque.offer(root.left);
}
if (root.right != null) {
deque.offer(root.right);
}
size--;
}
// End of each layer
}
return result;
}
}
边栏推荐
- 力扣 729. 我的日程安排表 I
- C language OJ gets PE, OJ of ACM introduction~
- S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
- 中金财富在网上开户安全吗?
- [C language] three implementations of quick sorting and optimization details
- Recommended collection, my Tencent Android interview experience sharing
- ACM getting started Day1
- 建议收藏,我的腾讯Android面试经历分享
- Is it safe to open a mobile stock account? Is it reliable?
- Force buckle 729 My schedule I
猜你喜欢
【硬核干货】数据分析哪家强?选Pandas还是选SQL
Let's talk about threadlocalinsecurerandom
aggregate
Elk distributed log analysis system deployment (Huawei cloud)
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
40000 word Wenshuo operator new & operator delete
14. Users, groups, and permissions (14)
js实现禁止网页缩放(Ctrl+鼠标、+、-缩放有效亲测)
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
随机推荐
ACM getting started Day1
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
1: Citation;
成功入职百度月薪35K,2022Android开发面试解答
C - sequential structure
leetcode刷题:二叉树15(找树左下角的值)
Is it safe for CICC fortune to open an account online?
That's awesome. It's enough to read this article
Build your own website (16)
Is it safe for Anxin securities to open an account online?
Tasks in GStreamer
95后阿里P7晒出工资单:狠补了这个,真香...
c语言oj得pe,ACM入门之OJ~
【硬核干货】数据分析哪家强?选Pandas还是选SQL
Jvmrandom cannot set seeds | problem tracing | source code tracing
Is it safe to open a mobile stock account? Is it reliable?
【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
How about testing outsourcing companies?
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件