```
class Solution(object):
def levelOrder(self, root):
r = []
def rec(root, k):
if root:
if len(r) < k+1:
r.append([])
r[k].append(root.val)
rec(root.left, k+1)
rec(root.right, k+1)
rec(root, 0)
return r
```