class Solution: def levelOrder(self , root: TreeNode) -> List[List[int]]: # write code here a=0 b=0 list_temp1=[]#存值 list_temp2=[]#存结点 List=[] now=root while now!=None: list_temp1.append(now.val) if now.left!=None: list_temp2.append(now.left) b+=1 if now.right!=None: list_temp2.append(now.right) b+=1 if a==0: List.append(list_temp1[:]) list_temp1.clear() a=b b=0 if list_temp2: now=list_temp2.pop(0) a-=1 else: break return List