当前位置:网站首页>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边栏推荐
- PostgreSQL learning 04 PG_ hint_ Plan installation and use, SQL optimization knowledge
- Mechanism and principle of multihead attention and masked attention
- 线性代数(三)
- (Niuke multi School II) j-link with arithmetic progress (least square method / three points)
- Run length test of R language: use the runs.test function to perform run length test on binary sequence data (check whether the sequence is random)
- Microservice configuration center Nacos
- 剑指 Offer 05. 替换空格
- 剖析kubernetes集群内部DNS解析原理
- 出于数据安全考虑,荷兰教育部要求学校暂停使用 Chrome 浏览器
- Differences and application directions of GPS, base station and IP positioning
猜你喜欢

Microservices and related component concepts

Realsense d435i depth map optimization_ High precision mode

Application of hard coding and streaming integration scheme based on spice protocol in cloud games

Programming hodgepodge (I)

Amazoncaptcha 95%成功率绕过亚马逊IP验证码

Ffmpeg notes (I) fundamentals of audio and video

剑指 Offer 54. 二叉搜索树的第k大节点

Softing pnGate系列网关:将PROFIBUS总线集成到PROFINET网络

sqlilabs less-28~less-8a

HTB-Optimum
随机推荐
(16)[系统调用]追踪系统调用(3环)
R language uses wilcox.test function to perform Wilcox signed rank test to obtain confidence interval of population median (set conf.level parameter to specify confidence level and size of confidence
求求你别再用 System.currentTimeMillis() 统计代码耗时了,真的太 Low 了!
R language data The table package performs aggregation transforms of data packets and calculates the grouping interquartile range (IQR) of dataframe data
传输线理论之相速、相位等的概念
HTB-Beep
What are the ways to realize web digital visualization?
Switch NPM source to private source library
Microservice - hystrix fuse
Leetcode 204. count prime numbers (wonderful)
Common methods of JS operation array
uniapp手机端uView的u-collapse组件高度init
Codeforces Round #809 (Div. 2)
2021 ICPC Shaanxi warm up match b.code (bit operation)
50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int
(2022牛客多校二)K-Link with Bracket Sequence I(动态规划)
(Niuke multi School II) G-LINK with monotonic subsequence (construction question)
HTB-Arctic
Matlab drawing example: 5: Biaxial graph
R language ggpubr package ggarrange function combines multiple images and annotates_ Figure add annotation, annotation, annotation information for the combined image, and use the right parameter to ad