当前位置:网站首页>Leetcode513. Find the value in the lower left corner of the tree
Leetcode513. Find the value in the lower left corner of the tree
2022-06-26 05:20:00 【Java full stack R & D Alliance】

Their thinking :
The value required by the title must be on the last level , That's for sure . So we just need to find the nodes of the last layer . Then we can do something .
So for such a tree , Let's go through the sequence , In fact, you can traverse from the right subtree of the tree , Then traverse the left subtree , So let's queue up for the last element , It is the leftmost element of the deepest layer we are looking for .
Do you feel , For this question , Breadth first algorithm , Easier and more suitable for
The code is as follows :
class Solution {
public int findBottomLeftValue(TreeNode root) {
Queue<TreeNode> queue = new LinkedList<>();
queue.offer(root);
while(!queue.isEmpty()){
root = queue.poll();
if (root.right != null) queue.offer(root.right);
if (root.left != null) queue.offer(root.left);
}
return root.val;
}
}
边栏推荐
- LSTM in tensorflow_ Layers actual combat
- Guanghetong and anti international bring 5g R16 powerful performance to the AI edge computing platform based on NVIDIA Jetson Xavier nx
- 慢慢学JVM之缓存行和伪共享
- Excellent learning ability is your only sustainable competitive advantage
- Day4 branch and loop jobs
- 红队得分方法统计
- Transport layer TCP protocol and UDP protocol
- Tensorflow and deep learning day 3
- [unity3d] rigid body component
- Apktool tool usage document
猜你喜欢

Install the tp6.0 framework under windows, picture and text. Thinkphp6.0 installation tutorial

Tp5.0 framework PDO connection MySQL error: too many connections solution

Yunqi lab recommends experience scenarios this week, free cloud learning

Classic theory: detailed explanation of three handshakes and four waves of TCP protocol

Codeforces Round #802 (Div. 2)(A-D)

Supplementary course on basic knowledge of IM development (II): how to design a server-side storage architecture for a large number of image files?

Transport layer TCP protocol and UDP protocol

Schematic diagram of UWB ultra high precision positioning system

LeetCode_二叉搜索树_简单_108.将有序数组转换为二叉搜索树

The localstorage browser stores locally to limit the number of forms submitted when tourists do not log in.
随机推荐
ECCV 2020 double champion team, take you to conquer target detection on the 7th
The localstorage browser stores locally to limit the number of forms submitted when tourists do not log in.
Technical past: tcp/ip protocol that has changed the world (precious pictures, caution for mobile phones)
cartographer_ backend_ constraint
First day of deep learning and tensorflow learning
cartographer_fast_correlative_scan_matcher_2d分支定界粗匹配
Transport layer TCP protocol and UDP protocol
Command line interface of alluxio
Supplementary course on basic knowledge of IM development (II): how to design a server-side storage architecture for a large number of image files?
Pytorch forecast house price
Baidu API map is not displayed in the middle, but in the upper left corner. What's the matter? Resolved!
Recursively traverse directory structure and tree presentation
Replacing domestic image sources in openwrt for soft routing (take Alibaba cloud as an example)
C# 40. byte[]与16进制string互转
cartographer_ optimization_ problem_ 2d
Thoughts triggered by the fact that app applications are installed on mobile phones and do not display icons
【Unity3D】人机交互Input
Muke.com actual combat course
Red team scoring method statistics
thread priority