当前位置:网站首页>Sword finger offer 32 - I. print binary tree from top to bottom, breadth first search (queue)
Sword finger offer 32 - I. print binary tree from top to bottom, breadth first search (queue)
2022-07-18 13:34:00 【The harder you work, the luckier you are】
The finger of the sword Offer 32 - I. Print binary tree 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边栏推荐
- 6、 JMeter timer
- 剑指 Offer 11. 旋转数组的最小数字
- 【深度学习】《动手学深度学习》环境配置
- 傲梅輕松克隆系統盤備份
- Expert routine of BW conversion based on AMDP
- Recursively solve the traversal of binary trees (often test basic examples)
- Some points for attention in drawing excel charts
- 双位置继电器DLS-5/1
- 剑指 Offer 42. 连续子数组的最大和
- Qunhui 7.1 add hard disk with SHR
猜你喜欢
![[notes] cryptography from introduction to earth | AES](/img/f8/6649d68018dad3c57b0864b4be0edd.png)
[notes] cryptography from introduction to earth | AES

EXCEL如何生成不重复的随机数 ,多方法+原理

layoutgan:generating graphic layouts with wiregrame discriminators

Batch stream fusion upgrade: Apache Flink 1.15.0 releases pulsar Flink sink connector

After Jay Chou's co branded model, Fang Wenshan brought online shopping to promote the collection of "Hualiu" top-level co branded dolls

DPR-34、AC220V双位置继电器

剑指 Offer 27. 二叉树的镜像

ES (6/7/8/9/10/11) notes
![[software testing] test slang, the advice given to you by ten-year old employees](/img/69/b27255c303150430df467ff3b5cd08.gif)
[software testing] test slang, the advice given to you by ten-year old employees

Problems encountered in deploying edusoho on the Intranet
随机推荐
[machine learning] integrated learning - ensemble learning
潮玩华猫来袭丨继周杰伦联名款后 ,方文山携上链购再推“华流”顶流联名款公仔数藏
探索式软件测试
Dls-42/4-4 dc110v double position relay
衡量两个分布的差距的工具:交叉熵和KL散度
Go: about grpc
剑指 Offer 27. 二叉树的镜像
DzzOffice_ Flowplayer player changes
[notes] overview of cryptography from introduction to earth
Some points for attention in drawing excel charts
快速上手Jupyter Notebook
Exploratory software testing
Three horses join hands with Qianyuan public welfare foundation | cool in summer, pay tribute to the adherents!
Test logiciel exploratoire
求水仙花数
三匹马携手乾元公益基金会 | 炎夏送清凉,致敬坚守者 !
130 多家企业,3500 多位开发者,共建 openGauss 开源数据库根社区
EXCEL,选择数据如何选择合适的图表?
剑指 Offer 18. 删除链表的节点
Excel, how to choose the right chart?