C语言 | Leetcode C语言题解之第435题无重叠区间
题目:
题解:
int cmp(int** a, int** b) {
return (*a)[1] - (*b)[1];
}
int eraseOverlapIntervals(int** intervals, int intervalsSize, int* intervalsColSize) {
if (intervalsSize == 0) {
return 0;
}
qsort(intervals, intervalsSize, sizeof(int*), cmp);
int right = intervals[0][1];
int ans = 1;
for (int i = 1; i < intervalsSize; ++i) {
if (intervals[i][0] >= right) {
++ans;
right = intervals[i][1];
}
}
return intervalsSize - ans;
}