题目描述
从上往下打印出二叉树的每个节点,同层节点从左至右打印。
class Solution: # 返回从上到下每个节点值列表,例:[1,2,3] def PrintFromTopToBottom(self, root): # write code here queen=[] res=[] if root is not None: queen.append(root) while len(queen) is not 0: temp=queen.pop(0) res.append(temp.val) if temp.left is not None: queen.append(temp.left) if temp.right is not None: queen.append(temp.right) return res