in python:

```
def eraseOverlapIntervals(self, intervals):
end = float('-inf')
result = len(intervals)
for interval in sorted(intervals, key=lambda x: x.end):
if interval.start >= end:
end = interval.end
result -= 1
return result
```

and in java:

```
public int eraseOverlapIntervals(Interval[] intervals) {
Arrays.sort(intervals, (o1, o2) -> Integer.compare(o1.end, o2.end));
int end = Integer.MIN_VALUE;
int result = intervals.length;
for (Interval interval : intervals) {
if (interval.start >= end) {
end = interval.end;
result -= 1;
}
}
return result;
}
```