当前位置:网站首页>Sword finger offer 32 - I. print binary tree from top to bottom
Sword finger offer 32 - I. print binary tree from top to bottom
2022-07-25 05:46:00 【The harder you work, the luckier you are】
The finger of the sword Offer 32 - I. Print binary from top to bottom
- Binary tree Top to bottom Print ( Print by layer ), Also known as binary tree Breadth first search (BFS).
- BFS Usually with queue The first in first out feature of .
import collections
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
def levelOrder(self,root):
res,qu=[],collections.deque()
if bool(root)==0:
return []
qu.append(root)
while qu:
tmp=qu.popleft()
res.append(tmp.val)
if tmp.left:
qu.append(tmp.left)
if tmp.right:
qu.append(tmp.right)
return res边栏推荐
- Atof(), atoi(), atol() functions [detailed]
- MATLAB作图实例:5:双轴图
- idea常用10个快捷键
- R language Visual scatter diagram, geom using ggrep package_ text_ The repl function avoids overlapping labels between data points (set the hJust parameter to show that labels of all data points are a
- 剑指 Offer 36. 二叉搜索树与双向链表
- 剖析kubernetes集群内部DNS解析原理
- Dynamic planning learning notes
- Softing pnGate系列网关:将PROFIBUS总线集成到PROFINET网络
- Siggraph 2022 -- rendering iridescent rock dove neck feathers
- Continuous maximum sum and judgement palindrome
猜你喜欢

(牛客多校二)G-Link with Monotonic Subsequence(构造题)

(2022 Niuke multi School II) l-link with level editor I (dynamic planning)

线性代数(三)

求求你别再用 System.currentTimeMillis() 统计代码耗时了,真的太 Low 了!

Difference between NPX and NPM

sqlilabs less-29

HTB-Granpa

Microservices and related component concepts

Mechanism and principle of multihead attention and masked attention

Concepts of phase velocity and phase in transmission line theory
随机推荐
Base64 (conversion between string and Base64 string)
(15)[驱动开发]过写拷贝
HTB-Optimum
The difference between $write and $display in SystemVerilog
(Niuke multi School II) j-link with arithmetic progress (least square method / three points)
(牛客多校二)J-Link with Arithmetic Progression(最小二乘法/三分)
Y76. Chapter IV Prometheus large factory monitoring system and practice -- Prometheus advanced (VII)
Leetcode 204. 计数质数(太妙了)
剑指 Offer 05. 替换空格
Unity accesses chartandgraph chart plug-in
Microservice - remote invocation (feign component)
easyrecovery免费数据恢复工具操作简单一键恢复数据
R language uses LM function to build multiple linear regression model and write regression equation according to model coefficient
A little experience about von Mises distribution
Sword finger offer 05. replace spaces
Era5 dataset description
Please stop using system The currenttimemillis() statistical code is time-consuming, which is really too low!
R language obtains the data row where the nth maximum value of the specified data column is located in the data.table data
Get URL of [url reference]? For the following parameters, there are two ways to get the value of the corresponding parameter name and convert the full quantity to the object structure
Bug --- redis deserialization failed