mycode 98.56%
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def levelOrder(self, root): """ :type root: TreeNode :rtype: List[List[int]] """ def deal(root,level): if not root: return if len(self.res) <= level: self.res.append([root.val]) else: self.res[level].append(root.val) deal(root.left,level+1) deal(root.right,level+1) self.res = [] deal(root,0) return self.res