class Solution:
def levelOrder(self , root: TreeNode) -> List[List[int]]:
if not root:return []
ans,que = [],[root]
# 遍历每一层
while que:
res = []
# 遍历当前层每个结点
for _ in range(len(que)):
node = que[0]
res.append(node.val)
que.pop(0)
if node.left :que.append(node.left)
if node.right :que.append(node.right)
ans.append(res)
return ans