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;
}
原文地址:https://blog.csdn.net/m0_59237910/article/details/142504279
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!