题目描述
blablabla
样例
blablabla
算法1
class Solution(object):
def printFromTopToBottom(self, root):
"""
:type root: TreeNode
:rtype: List[List[int]]
"""
if not root:
return []
stack = []
result = []
stack.append(root)
while stack:
tmp = []
for i in range(len(stack)):
cur = stack.pop(0)
tmp.append(cur.val)
if cur.left:
stack.append(cur.left)
if cur.right:
stack.append(cur.right)
result.append(tmp)
return result