```
from collections import defaultdict
def dfs(node, n, store):
if not node:
return
store[n].append(node.val)
dfs(node.left, n+1, store)
dfs(node.right, n+1, store)
class Solution(object):
def levelOrder(self, root):
"""
:type root: TreeNode
:rtype: List[List[int]]
"""
store = defaultdict(list)
dfs(root, 0, store)
return [l for _, l in sorted(store.iteritems())]
```