码迷,mamicode.com
首页 > 其他好文 > 详细

253. Meeting Rooms II

时间:2017-11-23 19:49:34      阅读:627      评论:0      收藏:0      [点我收藏+]

标签:and   empty   require   conf   tar   div   str   art   struct   

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

标签:and   empty   require   conf   tar   div   str   art   struct   

原文地址:http://www.cnblogs.com/jxr041100/p/7885690.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!