这就是#102变个形式输出
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def levelOrderBottom(self, root: TreeNode) -> List[List[int]]:
queue = collections.deque()
res = []
queue.append(root)
while queue:
tmp = []
n = len(queue)
for _ in range(n):
cur = queue.popleft()
if not cur:
continue
tmp.append(cur.val)
queue.append(cur.left)
queue.append(cur.right)
if tmp:
res.insert(0,tmp)
return res