Help finding me the error in my code

programming
Tags: #<Tag:0x00007f24256262b8>

#1

I dont know where am i going wrong please can some one help me find error in my code

bool com(pair<int,int> a, pair<int,int> b){
return a.first<b.first;
}
vector Solution::merge(vector &A) {
int n = A.size();
vector<pair<int,int>> p;
for(int i=0;i<n;i++){
p.push_back(make_pair(A[i].start,1));
p.push_back(make_pair(A[i].end,0));
}
sort(p.begin(),p.end(),com);
vector ans;
int on = 0;
int start = 0;
int end = 0;
for(int i=0;i<n;i++){
if(p[i].second == 1){
if(on == 0){
start = p[i].first;
}
on++;
}else{
on–;
if(on == 0){
end = p[i].first;
Interval temp(start,end);
ans.push_back(temp);
}
}
}
return ans;
}