my solution
bool mycomp(pair<TreeNode*,int> a,pair<TreeNode*,int> b)
{
return a.second<b.second;
}
vector Solution::solve(TreeNode* A) {
vector<vector > v;
if(A == NULL)return v;
queue<pair <TreeNode*, int> > q;
q.push({A, 0});
map<int, vector<int> > mp;
while(!q.empty()){
pair<TreeNode*, int> temp = q.front();
q.pop();
if(temp.first->left){
q.push({temp.first->left, temp.second-1});
}
if(temp.first->right){
q.push({temp.first->right, temp.second+1});
}
mp[temp.second].push_back(temp.first->val);
}
for(map<int, vector<int> >::iterator it = mp.begin(); it != mp.end(); it++){
v.push_back(it->second);
}
return v;
}
please tell me why all test cases are not passing