253. Meeting Rooms II

Posted jxr041100

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了253. Meeting Rooms II相关的知识,希望对你有一定的参考价值。

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required.

For example,
Given [[0, 30],[5, 10],[15, 20]],
return 2.

/**
 * Definition for an interval.
 * struct Interval {
 *     int start;
 *     int end;
 *     Interval() : start(0), end(0) {}
 *     Interval(int s, int e) : start(s), end(e) {}
 * };
 */
class Solution {
public:
    int minMeetingRooms(vector<Interval>& intervals) {
        sort(intervals.begin(),intervals.end(),[](Interval a,Interval b){return a.start<b.start;});
        priority_queue<int,vector<int>, greater<int>> pq;
        int res=0;
        for(auto interval:intervals)
        {
            while(!pq.empty()&&interval.start>=pq.top()) pq.pop();
            pq.push(interval.end);
            int size = pq.size();
            res = max(res,size);
        }
        return res;
    }
};

 

以上是关于253. Meeting Rooms II的主要内容,如果未能解决你的问题,请参考以下文章

253. Meeting Rooms II

253. Meeting Rooms II

253. Meeting Rooms II

253 Meeting Rooms II

LeetCode 253. Meeting Rooms II(会议室)

Leetcode 253: Meeting Rooms II