/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } }; */ #include <vector> class Solution { public: vector<vector<int>> ans; vector<vector<int>> Print(TreeNode* pRoot,int x=0) { if(pRoot==nullptr){ return ans; } if(ans.size()<x+1){ vector<int> t; ans.push_back(t); } ans[x].push_back(pRoot->val); Print(pRoot->left,x+1); Print(pRoot->right,x+1); return ans; } };