当前位置:网站首页>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;
}
}
边栏推荐
- 成功入职百度月薪35K,2022Android开发面试解答
- 通配符选择器
- DP:树DP
- That's awesome. It's enough to read this article
- After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
- 【c语言】快速排序的三种实现以及优化细节
- 《乔布斯传》英文原著重点词汇笔记(十二)【 chapter ten & eleven】
- Force buckle 1200 Minimum absolute difference
- Is it safe to open a mobile stock account? Is it reliable?
- Wildcard selector
猜你喜欢
再忙不能忘安全
Postman core function analysis - parameterization and test report
Zhongang Mining: analysis of the current market supply situation of the global fluorite industry in 2022
C application interface development foundation - form control (5) - grouping control
解决php无法将string转换为json的办法
Common - Hero Minesweeper
Let's talk about threadlocalinsecurerandom
众昂矿业:2022年全球萤石行业市场供给现状分析
IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times
Go language | 02 for loop and the use of common functions
随机推荐
Float. The specific meaning of the return value of floattorawintbits is to convert float into byte array
中金财富在网上开户安全吗?
函数的概念及语法
Thread pool parameters and reasonable settings
Add data to excel small and medium-sized cases through poi
How to apply smart contracts more wisely in 2022?
third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
手机股票开户安全吗?靠不靠谱啊?
Interviewer: what is the internal implementation of set data types in redis?
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
40000 word Wenshuo operator new & operator delete
IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times
C application interface development foundation - form control (6) - menu bar, toolbar and status bar controls
leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
ICTCLAS用的字Lucene4.9捆绑
【obs】libobs-winrt :CreateDispatcherQueueController
leetcode刷题:二叉树11(平衡二叉树)
国信证券在网上开户安全吗?
Reptile exercises (II)
C application interface development foundation - form control (5) - grouping control