forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path253.Meeting-Rooms-II.cpp
45 lines (42 loc) · 1.02 KB
/
253.Meeting-Rooms-II.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* 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 {
static bool cmp1(Interval a, Interval b)
{
return a.start<b.start;
}
struct cmp2
{
bool operator()(Interval a, Interval b)
{
return a.end>b.end;
}
};
public:
int minMeetingRooms(vector<Interval>& intervals)
{
sort(intervals.begin(),intervals.end(),cmp1);
priority_queue<Interval,vector<Interval>,cmp2>pq;
int count=0;
int i=0;
while (i<intervals.size())
{
while (pq.empty() || i<intervals.size() && pq.top().end>intervals[i].start)
{
pq.push(intervals[i]);
i++;
}
int n=pq.size();
count=max(count,n);
pq.pop();
}
return count;
}
};