My Java Solution


  • 0
    E
    public class Solution {
        public int eraseOverlapIntervals(Interval[] intervals) {
            if(intervals.length <= 0) return 0;
            Arrays.sort(intervals, (a,b) -> a.end - b.end);
            int border = intervals[0].end;
            int erase = 0;
            for(int i = 1; i < intervals.length; i++) {
                if(intervals[i].start < border) erase++;
                else {
                    border = intervals[i].end;
                }
            }
            return erase;
        }
    }
    

Log in to reply
 

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