Using map to store level elements


#1
*/

void fxn(TreeNodeA,map<int,vector>&m,int k)
{
if(A==NULL)
return ;
m[k].push_back(A->val);
fxn(A->left,m,k+1);
fxn(A->right,m,k+1);
}
vector Solution::solve(TreeNode
A) {
map<int,vector>m;
fxn(A,m,0);
vectorans;
int n=m.size();
for(int i=0;i<n;i++)
{
for(int j=0;j<m[n-1-i].size();j++)
ans.push_back(m[n-1-i][j]);
}
return ans;

}