当前位置:网站首页>leetcode:515. 在每个树行中找最大值【无脑bfs】
leetcode:515. 在每个树行中找最大值【无脑bfs】
2022-06-24 19:30:00 【白速龙王的回眸】

分析
无脑bfs
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 largestValues(self, root: Optional[TreeNode]) -> List[int]:
if not root:
return []
ans = []
q = [root]
while q:
new_q = []
maxn = -inf
for node in q:
maxn = max(maxn, node.val)
if node.left: new_q.append(node.left)
if node.right: new_q.append(node.right)
ans.append(maxn)
q = new_q
return ans
总结
无脑bfs
边栏推荐
- 好想送对象一束花呀
- That is to say, "live broadcast" is launched! One stop live broadcast service with full link upgrade
- Xinlou: Huawei's seven-year building journey of sports health
- Notes on writing questions (18) -- binary tree: common ancestor problem
- 最大流问题
- 火狐拖放后,总会默认打开百度搜索,如果是图片,则会打开图片。
- I really can't do it. After 00, I collapsed and wanted to leave
- Object.defineProperty和Reflect.defineProperty的容错问题
- Graduation design of phase 6 of the construction practice camp
- [notes of Wu Enda] multivariable linear regression
猜你喜欢

Vscode netless environment rapid migration development environment (VIP collection version)

Want to be a test leader, do you know these 6 skills?

基于 KubeSphere 的分级管理实践

Practice of hierarchical management based on kubesphere

cv2导包时报Could not find a version that satisfies the requirement cv2 (from versions: none)

权限想要细化到按钮,怎么做?
![[notes of Wu Enda] convolutional neural network](/img/19/2cac17010c29cbd5ba245de105d6c1.png)
[notes of Wu Enda] convolutional neural network

Machine learning: linear regression

是真干不过00后,给我卷的崩溃,想离职了...
![在每个树行中找最大值[分层遍历之一的扩展]](/img/5b/81ff20b61c0719ceb6873e44878859.png)
在每个树行中找最大值[分层遍历之一的扩展]
随机推荐
ST表+二分
Summary of papers on traveling salesman problem (TSP)
Fuzhou business office of Fujian development and Reform Commission visited the health department of Yurun university to guide and inspect the work
C语言-关键字1
St Table + two points
滤波数据分析
将二维数组方阵顺时针旋转90°
应用实践 | 海量数据,秒级分析!Flink+Doris 构建实时数仓方案
A deep learning model for urban traffic flow prediction with traffic events mined from twitter
Maximum flow problem
Réduire le PIP à la version spécifiée (mettre à jour le PIP avec pycharm avant de le réduire à la version originale)
How to refine permissions to buttons?
leetcode:1504. 统计全 1 子矩形的个数
如何化解35岁危机?华为云数据库首席架构师20年技术经验分享
cv2导包时报Could not find a version that satisfies the requirement cv2 (from versions: none)
专科出身,2年进苏宁,5年跳阿里,论我是怎么快速晋升的?
Elegant custom ThreadPoolExecutor thread pool
Development trend and path of SaaS industry in China
性能测试工具wrk安装使用详解
leetcode_191_2021-10-15