Non Overlapping Intervals

  • 0

    Click here to see the full article post

  • 0

    The greedy approach is so brilliant!

  • 0

    Here my my code to use the lambda expression to make the code short.

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

  • 0

    Hope Leetcode editor team do writing-proof before final publishing. These article words sound weird.

Log in to reply

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