# 【Python】【难度：简单】Leetcode 面试题32 - II. 从上到下打印二叉树 II

3
/ \
9  20
/  \
15   7

[
[3],
[9,20],
[15,7]
]

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
def levelOrder(self, root):
"""
:type root: TreeNode
:rtype: List[List[int]]
"""
if not root:
return []

queue=[root]
res=[]

while queue:
var=[]
nxt=[]

for node in queue:
var.append(node.val)
if node.left:
nxt.append(node.left)
if node.right:
nxt.append(node.right)
res.append(var)
queue=nxt

return res

05-14 38

05-05 81

04-15 3693

05-14 41

05-23 26

05-04 39

02-28 26

03-06 113

03-07 35

03-07 29

09-22 176

09-05 1344

07-20 4894

09-05 188

06-03 5567

07-26 2200

08-05 2906

02-27 38

04-22 53

04-14 59万+

03-13 15万+

02-19 18万+

03-04 14万+

03-06 2171

03-08 2万+

04-25 6万+

03-10 13万+

03-10 18万+

03-12 11万+

03-13 11万+

03-16 1786

03-18 1万+

03-19 8万+

03-19 3万+

03-20 9638

03-22 4683

03-23 4万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-27 5万+

03-29 21万+

03-29 10万+

03-30 16万+

05-31 6800

04-02 6224

04-02 4万+

05-31 264

04-06 1万+

04-06 7万+

04-06 3399

04-09 8万+

04-09 3万+

05-17 9136

04-11 4万+

04-15 6万+

04-18 4万+

04-20 4万+

04-24 3万+

05-03 1万+

05-16 5万+

05-06 1万+

05-06 2308

05-07 4044

05-08 4万+

05-10 3621

05-11 2630

05-14 6934

05-14 1233

05-16 3884

05-16 1万+

05-17 5361

05-30 1282

05-18 2506

05-18 8815

05-18 3918

05-19 1万+

#### 一个晚上，我学会了24种开发语言！

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客