编程语言
首页 > 编程语言> > 贪心算法-435

贪心算法-435

作者:互联网

 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 }

 

标签:right,const,int,max,intervalsSize,算法,intervals,435,贪心
来源: https://www.cnblogs.com/ainingxiaoguai/p/16463536.html