LeetCode打卡81

tech2022-12-29  121

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; }
最新回复(0)