AcWing 43. 不分行从上往下打印二叉树-python
原题链接
简单
作者:
acwing_827
,
2019-09-04 17:35:04
,
所有人可见
,
阅读 1308
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def printFromTopToBottom(self, root):
"""
:type root: TreeNode
:rtype: List[int]
"""
res = []
if not root: return []
q = [root]
while q:
node = q.pop(0)
res.append(node.val)
if node.left: q.append(node.left)
if node.right: q.append(node.right)
return res