# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None from collections import deque classSolution(object): deflevelOrder(self, root): """ :type root: TreeNode :rtype: List[List[int]] """ ifnot root:return [] q = deque() q.append(root) res = [] while q: tmp = [] n = len(q) for i in range(n): node = q.popleft() tmp.append(node.val) if node.left:q.append(node.left) if node.right:q.append(node.right) res.append(tmp) return res