```
class Solution(object):
def levelOrder(self, root):
res = []
self.BFS(root, res, 0)
return res
def BFS(self, root, res, level):
if not root:
return
try:
res[level].append(root.val)
except:
res.append([])
res[level].append(root.val)
self.BFS(root.left, res, level+1)
self.BFS(root.right, res, level+1)
```