435. Non-overlapping Intervals


  • 0
    T

    class Solution {
    public:

    int eraseOverlapIntervals(vector<Interval>& intervals) {
        int len=intervals.size();
        if(len<=1) return 0;
       sort(intervals.begin(),intervals.end(),[](Interval a,Interval b){  
           return a.end<b.end; });  
        int sum=1,r=intervals[0].end;
        for(int x=1;x<len;x++)
            if(intervals[x].start>=r) sum++,r=intervals[x].end;
        return len-sum;
    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.