# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def levelOrder(self, root: TreeNode) -> List[List[int]]:
al=[]
if not root:
return al
stack=[root]
ls=[]
tem=[]
while(stack):
index=stack.pop(0)
if index:
ls.append(index.val)
tem.append(index.left)
tem.append(index.right)
if not stack and ls:
stack=tem[:]
al.append(ls[:])
ls=[]
tem=[]
return al