当前位置:网站首页>leetcode:513. 找树左下角的值【简单bfs找每层第一个】
leetcode:513. 找树左下角的值【简单bfs找每层第一个】
2022-04-21 13:13:00 【白速龙王的回眸】

分析
用while + queue找到每层第一个记录就好
ac code
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def findBottomLeftValue(self, root: Optional[TreeNode]) -> int:
# 传统bfs
q = [root]
ans = root.val
while q:
ans = q[0].val
qLen = len(q)
new_q = []
for i in range(qLen):
if q[i].left:
new_q.append(q[i].left)
if q[i].right:
new_q.append(q[i].right)
q = new_q
return ans
总结
无脑bfs
版权声明
本文为[白速龙王的回眸]所创,转载请带上原文链接,感谢
https://bridge-killer.blog.csdn.net/article/details/124315975
边栏推荐
- [UVM] multi module env structure
- In depth analysis of focal loss loss function
- 【数字信号处理】相关函数 ( 能量信号 | 能量信号的互相关函数 | 能量信号的自相关函数 )
- Q: How to change the number of appendix in the paper with the text.
- 53W words! Ali's first system performance optimization guide is so fragrant that it can be called the optimal solution of performance optimization
- The packaged jar can run normally and connect to the database normally. Exe4j generates exe and reports an error when accessing the database:
- 让你的代码更优秀的 14 条建议
- 乡村vlog收割8000w+播放,又一个流量天花板?
- The second development of Revit -- how to use lookup (phase VII)
- 安装和配置Canal
猜你喜欢

Wanzi dry goods! Help you master the knowledge of "light and shadow" in design

3、 Label preparation

Go language file operation

2021-08-10

Jiaozuo Third People's Hospital joined hands with meichuang to open a new situation of data security construction

How do we media create hot articles and improve reading volume

twenty million two hundred and ten thousand eight hundred and twelve

美创科技受邀为海淀区教育科学研究院开展数据安全培训

Village vlog harvest 8000w + play, another flow ceiling?

Wanzi dry goods! Help you deeply master the knowledge points of "light and shadow" in design (Part 2)
随机推荐
Eight common probability distribution formulas and visualization
How a person makes self media videos, and the operation skills in the field of agriculture, rural areas and farmers
[digital signal processing] linear constant coefficient difference equation (determine whether the system is a "linear time invariant system" according to "linear constant coefficient difference equat
(建议精读)this指北
Network communication protocol model
滑动窗口系列-寻找最小覆盖字串
QFileInfo文件和文件夹操作
美创科技受邀为海淀区教育科学研究院开展数据安全培训
Algorithem_Populating Next Right Pointers in Each Node
OJ每日一练——数组倒序输出新数组
大才能否小用?OceanBase一体化场景测试
通信协议英语单词解析
Why does MySQL driver rely on protobuf
Revit二次开发——创建墙体(2)(第十一期)
S:单位增益补偿
How do we media create hot articles and improve reading volume
Q: How to change the number of appendix in the paper with the text.
UGUI-- Button 按钮组件
Algorithem_ Populating Next Right Pointers in Each Node
滑動窗口系列-尋找最小覆蓋字串