```
class Solution {
public:
vector<vector<int> > ret;
void dfs(TreeNode *node, int level){
if (node == NULL) return;
if (ret.size() <= level) ret.resize(level+1);
ret[level].push_back(node->val);
dfs(node->left, level+1);
dfs(node->right, level+1);
}
vector<vector<int> > levelOrder(TreeNode *root) {
dfs(root, 0);
return ret;
}
};
```

This is done by the property of pre-order traversal.