C语言刷leetcode——贪心

贪心

  • 找到贪心策略,使得:局部最优解-->整体最优解

刷题

252. 会议室(P)

image

253. 会议室 II (P)

#define MAX 1000001
int minMeetingRooms(int** intervals, int intervalsSize, int* intervalsColSize) {
    int diff[MAX] = {0};
    for (int i = 0; i < intervalsSize; i++) {
        diff[intervals[i][0]] += 1;
        diff[intervals[i][1]] -= 1;
    }
    int ret = 0;
    long sum = 0;
    for (int i = 0; i < MAX; i++) {
        sum += diff[i];
        ret = fmax(sum, ret);
    } 
    return ret;
}

image

image

https://leetcode.cn/problems/meeting-rooms-ii/solutions/2081316/labuladong-sao-miao-xian-ji-qiao-an-pai-h0f5d/

https://leetcode.cn/problems/meeting-rooms-ii/solutions/950111/253hui-yi-shi-ii-pai-xu-bian-li-by-agven-49qp/
image

1353. 最多可以参加的会议数目

posted @ 2023-05-13 17:52  胖白白  阅读(17)  评论(0编辑  收藏  举报