Solution c++ easy to understand


#1

#define pb push_back
#define ff first
#define ss second

bool fass(pair<int,int>a,pair<int,int>b)

{
if(a.ff<b.ff)
{
return true;
}
else if(a.ff==b.ff)
{
if(a.ss<b.ss)
{
return false;
}
return true;

}
return false;

}

int Solution::solve(vector<vector > &A) {
vector<pair<int,int>>v;
for(int i=0;i<A.size();i++)
{
v.pb({A[i][0],0});
v.pb({A[i][1],1});
}
sort(v.begin(),v.end(),fass);
int ans=0,cnt=0;
for(int i=0;i<v.size();i++)
{
if(v[i].ss==0)
{
cnt++;
}
else if(v[i].ss==1)
{
cnt–;
}
ans=max(ans,cnt);
}
return ans;

}