#熟悉Queue容器的 的 .put() .get() .empty()用法
# -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
import Queue #python2为import Queue / python3中为 import queue
class Solution:
# 返回从上到下每个节点值列表,例:[1,2,3]
def PrintFromTopToBottom(self, root):
# write code here
if not root:
return []
q=Queue.Queue()
q.put(root)
res=[]
while not q.empty():
node=q.get()
res.append(node.val)
if node.left:
q.put(node.left)
if node.right:
q.put(node.right)
return res