题目描述:
方法一;
class Solution(object): def levelOrder(self, root): """ :type root: TreeNode :rtype: List[List[int]] """ if not root: return [] ans = [] stack = [root] while stack: tem_stack = [] tem_ans = [] for i in stack: tem_ans.append(i.val) if i.left: tem_stack.append(i.left) if i.right: tem_stack.append(i.right) stack = tem_stack ans.append(tem_ans) return ans