int MyCmp(const void **a
, const void **b
){
return (*(int**)a
)[1] - (*(int**)b
)[1];
}
int eraseOverlapIntervals(int** intervals
, int intervalsSize
, int* intervalsColSize
){
if (intervalsSize
== 0) return 0;
qsort(intervals
, intervalsSize
, sizeof(int*), MyCmp
);
int x_end
= intervals
[0][1];
int start
;
int count
= 1;
for (int i
= 1; i
< intervalsSize
; i
++) {
start
= intervals
[i
][0];
if (start
>= x_end
) {
count
++;
x_end
= intervals
[i
][1];
}
}
return intervalsSize
- count
;
}
转载请注明原文地址:https://tech.qufami.com/read-8571.html