. 1 # - * - Coding: UTF- . 8 - * - 2 # class the TreeNode: . 3 # DEF the __init __ (Self, X): . 4 # self.val = X . 5 # self.left = None . 6 # self.right = None . 7 class Solution: . 8 # returns the value of each node list from top to bottom, for example: [ . 1 , 2 , . 3 ] . 9 DEF the __init __ (Self): 10 self.list = [] . 11 12 is DEF levelOrder (Self, Level): 13 is count = len(level) 14 while count > 0: 15 root = level.pop(0) 16 self.list.append(root.val) 17 if root.left != None: 18 level.append(root.left) 19 if root.right != None: 20 level.append(root.right) 21 count -= 1 22 if len(level) > 0: 23 self.levelOrder(level) 24 25 26 def PrintFromTopToBottom(self, root): 27 if root == None: 28 return self.list 29 else: 30 level = [] 31 level.append(root) 32 self.levelOrder(level) 33 return self.list 34 # write code here