```
class Solution {
public int eraseOverlapIntervals(Interval[] intervals) {
if(intervals.length == 0)
return 0;
Arrays.sort(intervals, (i1, i2) -> {
if(i1.start == i2.start)
return i1.end - i2.end;
return i1.start - i2.start;
});
int count = 0;
int end = intervals[0].end;
for(int i = 1; i < intervals.length; i++){
if(intervals[i].start < end){
end = Math.min(intervals[i].end, end);
count++;
}
else{
end = Math.max(intervals[i].end, end);
}
}
return count;
}
}
```