# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # # # @param root TreeNode类 # @return int整型二维数组 # class Solution: def levelOrder(self , root ): def do(root ,level): if root == None: return else: if len(self.treelist) < level: self.treelist.append([]) self.treelist[level-1].append(root.val) if root.left != None: do(root.left, level+1) if root.right != None: do(root.right, level+1) # write code here self.treelist = [] do(root,1) return self.treelist