当前位置:网站首页>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;
}
}
边栏推荐
- The first gift of the project, the flying oar contract!
- 出色的学习能力,才是你唯一可持续的竞争优势
- Apktool tool usage document
- 程序人生
- Why does the mobile IM based on TCP still need to keep the heartbeat alive?
- 第九章 设置结构化日志记录(一)
- How MySQL deletes all redundant duplicate data
- 数据存储:MySQL之InnoDB与MyISAM的区别
- 基于SDN的DDoS攻击缓解
- Tensorflow visualization tensorboard "no graph definition files were found." error
猜你喜欢

【ARM】讯为rk3568开发板buildroot添加桌面应用

6.1 - 6.2 公钥密码学简介

LeetCode 19. Delete the penultimate node of the linked list

Ad tutorial series | 4 - creating an integration library file

ECCV 2020 double champion team, take you to conquer target detection on the 7th

Transport layer TCP protocol and UDP protocol

Henkel database custom operator '~~‘

6.1 - 6.2 公鑰密碼學簡介

【Unity3D】碰撞体组件Collider
Protocol selection of mobile IM system: UDP or TCP?
随机推荐
skimage. morphology. medial_ axis
What is UWB in ultra-high precision positioning system
Two step processing of string regular matching to get JSON list
Learn from small samples and run to the sea of stars
C# 40. Byte[] to hexadecimal string
9 common classes
Official image acceleration
cartographer_ local_ trajectory_ builder_ 2d
【红队】要想加入红队,需要做好哪些准备?
cartographer_local_trajectory_builder_2d
data = self._ data_ queue. get(timeout=timeout)
Cookie and session Basics
Supplementary course on basic knowledge of IM development (II): how to design a server-side storage architecture for a large number of image files?
《财富自由之路》读书之一点体会
Wechat team sharing: technical decryption behind wechat's 100 million daily real-time audio and video chats
cartographer_fast_correlative_scan_matcher_2d分支定界粗匹配
Happy New Year!
递归遍历目录结构和树状展现
GD32F3x0 官方PWM驱动正频宽偏小(定时不准)的问题
【ARM】在NUC977上搭建基于boa的嵌入式web服务器