当前位置:网站首页>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
边栏推荐
- 火狐拖放后,总会默认打开百度搜索,如果是图片,则会打开图片。
- 面试官:你说你精通Redis,你看过持久化的配置吗?
- ST表+二分
- [featured] how do you design unified login with multiple accounts?
- TypeScript快速入门
- 基于kruskal的最小生成树
- Find the maximum value in each tree row [extension of one of the hierarchical traversals]
- How to refine permissions to buttons?
- Practice of hierarchical management based on kubesphere
- 使用region折叠代码
猜你喜欢

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

leetcode-201_ 2021_ 10_ seventeen
![[camera Foundation (II)] camera driving principle and Development & v4l2 subsystem driving architecture](/img/b5/23e3aed317ca262ebd8ff4579a41a9.png)
[camera Foundation (II)] camera driving principle and Development & v4l2 subsystem driving architecture

The process from troubleshooting to problem solving: the browser suddenly failed to access the web page, error code: 0x80004005, and the final positioning: "when the computer turns on the hotspot, the
![[notes of Wu Enda] convolutional neural network](/img/19/2cac17010c29cbd5ba245de105d6c1.png)
[notes of Wu Enda] convolutional neural network

Graduation design of phase 6 of the construction practice camp

应用实践 | 海量数据,秒级分析!Flink+Doris 构建实时数仓方案

Several schemes of traffic exposure in kubernetes cluster

Make tea and talk about heroes! Leaders of Fujian Provincial Development and Reform Commission and Fujian municipal business office visited Yurun Health Division for exchange and guidance

leetcode:515. 在每个树行中找最大值【无脑bfs】
随机推荐
即构「畅直播」上线!提供全链路升级的一站式直播服务
Reduce the pip to the specified version (upgrade the PIP through pycharm, and then reduce it to the original version)
在每个树行中找最大值[分层遍历之一的扩展]
壹沓科技签约七匹狼,助力「中国男装领导者」数字化转型
Want to be a test leader, do you know these 6 skills?
Flutter-使用 typedef的注意事项
【论】Deep learning in the COVID-19 epidemic: A deep model for urban traffic revitalization index
linq查询集合类入门 案例武林高手类
[notes of Wu Enda] multivariable linear regression
Filtered data analysis
Flutter 如何使用在线转码工具将 JSON 转为 Model
是真干不过00后,给我卷的崩溃,想离职了...
基于 KubeSphere 的分级管理实践
01--- conditions for interference of two trains of waves at the meeting place
降低pip到指定版本(通過PyCharm昇級pip,在降低到原來版本)
滤波数据分析
cv2导包时报Could not find a version that satisfies the requirement cv2 (from versions: none)
You are using pip version 21.1.2; however, version 22.1.2 is available
These map operations in guava have reduced my code by 50%
Redis+caffeine two-level cache enables smooth access speed