Non Overlapping Intervals


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.endb.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; } }

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