当前位置:网站首页>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
边栏推荐
- 【吴恩达笔记】多变量线性回归
- Kubernetes 集群中流量暴露的几种方案
- Principle and application of queue implementation
- Getting started with typescript
- CV2 package guide times could not find a version that satisfies the requirement CV2 (from versions: none)
- Byte software testing basin friends, you can change jobs. Is this still the byte you are thinking about?
- Prompt that the device has no permission when using ADB to connect to the device
- Machine learning: linear regression
- TypeScript快速入门
- 拖动拖动拖动
猜你喜欢

LeetCode-513. 找树左下角的值
![[camera Foundation (I)] working principle and overall structure of camera](/img/5d/c29d636a90d01e5c3852df2a0dd833.png)
[camera Foundation (I)] working principle and overall structure of camera

Installing Oracle without graphical interface in virtual machine centos7 (nanny level installation)

【论】Deep learning in the COVID-19 epidemic: A deep model for urban traffic revitalization index

Flutter-使用 typedef的注意事项

Collapse code using region

SAP接口debug设置外部断点

降低pip到指定版本(通過PyCharm昇級pip,在降低到原來版本)

Introduce the overall process of bootloader, PM, kernel and system startup

性能测试工具wrk安装使用详解
随机推荐
Getting started with typescript
I really want to send a bunch of flowers
Introduce the overall process of bootloader, PM, kernel and system startup
双链表实现
How to refine permissions to buttons?
dp问题集
leetcode_ one thousand three hundred and sixty-five
You are using pip version 21.1.2; however, version 22.1.2 is available
You are using pip version 21.1.2; however, version 22.1.2 is available
壹沓科技签约七匹狼,助力「中国男装领导者」数字化转型
使用region折叠代码
平衡二叉搜索树
波卡生态发展不设限的奥义——多维解读平行链
Notes on writing questions (18) -- binary tree: common ancestor problem
机器学习:线性回归
Detailed installation and use of performance test tool wrk
MySQL gets fields and comments by indicating
Yida technology signed a contract with seven wolves to help the digital transformation of "Chinese men's wear leader"
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
Reduce the pip to the specified version (upgrade the PIP through pycharm, and then reduce it to the original version)