1 int cmp(const void ** a, const void **b) 2 { 3 int **p = (int **)a, **q = (int **)b; 4 return (*p)[1] - (*q)[1]; 5 } 6 7 int eraseOverlapIntervals(int** intervals, int intervalsSize, int* intervalsColSize){ 8 qsort(intervals, intervalsSize, sizeof(int *), cmp); 9 10 int max = 1; 11 int right = intervals[0][1]; 12 for (int i = 1; i < intervalsSize; i++) 13 { 14 if (intervals[i][0] >= right) 15 { 16 max++; 17 right = intervals[i][1]; 18 } 19 } 20 return intervalsSize - max; 21 }
原创文章,作者:306829225,如若转载,请注明出处:https://blog.ytso.com/273440.html