当前位置:网站首页>leetcode:515. Find the maximum value in each tree row [brainless BFS]
leetcode:515. Find the maximum value in each tree row [brainless BFS]
2022-06-24 22:04:00 【Review of the white speed Dragon King】

analysis
No brain 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
summary
No brain bfs
边栏推荐
- leetcode:55. 跳跃游戏【经典贪心】
- 02--- impossible phenomenon of longitudinal wave
- Multithreaded finalization
- 在每个树行中找最大值[分层遍历之一的扩展]
- Prompt that the device has no permission when using ADB to connect to the device
- How to resolve the 35 year old crisis? Sharing of 20 years' technical experience of chief architect of Huawei cloud database
- Junior college background, 2 years in Suning, 5 years in Ali. How can I get promoted quickly?
- 《各行业零代码企业应用案例集锦》正式发布
- 刷题笔记(十八)--二叉树:公共祖先问题
- TCP RTT测量妙计
猜你喜欢

“阿里健康”们的逻辑早就变了
![[notes of Wu Enda] convolutional neural network](/img/19/2cac17010c29cbd5ba245de105d6c1.png)
[notes of Wu Enda] convolutional neural network

Kubernetes 集群中流量暴露的几种方案

性能测试工具wrk安装使用详解

Multithreaded finalization

openGauss内核:简单查询的执行

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

壹沓科技签约七匹狼,助力「中国男装领导者」数字化转型

first-order-model实现照片动起来(附工具代码) | 机器学习

Several schemes of traffic exposure in kubernetes cluster
随机推荐
【吴恩达笔记】机器学习基础
想当测试Leader,这6项技能你会吗?
MySQL gets fields and comments by indicating
我国SaaS产业的发展趋势与路径
Graduation design of phase 6 of the construction practice camp
Junior college background, 2 years in Suning, 5 years in Ali. How can I get promoted quickly?
Flutter 库冲突问题解决
波卡生态发展不设限的奥义——多维解读平行链
架构实战营 第 6 期 毕业设计
TypeScript快速入门
【OpenCV 例程200篇】209. HSV 颜色空间的彩色图像分割
PyCharm 中出现Cannot find reference ‘imread‘ in ‘__init__.py‘
Redis+caffeine two-level cache enables smooth access speed
Summary of papers on traveling salesman problem (TSP)
leetcode1720_ 2021-10-14
[200 opencv routines] 209 Color image segmentation in HSV color space
Find the maximum value in each tree row [extension of one of the hierarchical traversals]
Introduce the overall process of bootloader, PM, kernel and system startup
Reduce the pip to the specified version (upgrade the PIP through CMP and reduce it to the original version)
Flutter-使用 typedef的注意事项