C++ Used Maps. Simple


#1
int max(int x, int y){
    if(x>y)
        return x;
    return y;
}
int Solution::solve(vector<vector<int> > &A) {
    sort(A.begin(), A.end());
    int ans = 0;
    int sum = 0;
    map<int,int> mp;
    for(int i = 0; i<A.size(); i++){
        ans = max(ans, sum);
        if(mp.empty()){
            sum = 1;
            mp[A[i][1]]++;
            continue;
        }
        map<int,int>::iterator itr = mp.begin();
        while(itr->first<=A[i][0]){
            int x = itr->first;
            sum-=itr->second;
            mp.erase(x);
            if(mp.empty())
                break;
            itr = mp.begin();
        }
        sum-=mp[A[i][1]];
        mp[A[i][1]]++;
        sum+=mp[A[i][1]];
    }
    ans = max(ans,sum);
    return ans;
}