Non Overlapping Intervals


  • 0

    Click here to see the full article post


  • 0
    C

    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){
                    count++;
                    lastEnd=intervals[i].end;
                }
            }
            return intervals.length - count;
        }
    }
    

  • 1
    B

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


  • 0

    Anyone having python not taking the dp n^2 approach ?


  • 0
    C

    The verbiage for Case 3 in Approach#5 should be corrected to:
    "The two intervals currently considered are overlapping and the starting point of the later interval falls AFTER the starting point of the previous interval:"

    Right now, the verbiage for Case 2 and Case 3 is the same.


  • 0
    X

    "The final result will be the total number of intervals given less the result just obtained(intervals.length-ansintervals.length−ans)."

    Thanks for the article, but notice that "less" is not a verb, the word you wanted in this sentence is probably "minus".


  • 0
    X

    @bigoffer4all totally agree. I found other articles by this writer very confusing too.


Log in to reply
 

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