/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
private:
vector<vector<int>> ret;
public:
void traversal(int dep, TreeNode *root) {
if(root == NULL)
return;
if(ret.size() > dep)
ret[dep].push_back(root->val);
else {
vector<int> tmp;
tmp.push_back(root->val);
ret.push_back(tmp);
}
traversal(dep + 1,root->left);
traversal(dep + 1,root->right);
}
vector<vector<int>> levelOrder(TreeNode* root) {
traversal(0, root);
return ret;
}
};