-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path253.cpp
56 lines (47 loc) · 1.05 KB
/
253.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
46
47
48
49
50
51
52
53
54
55
56
struct node
{
int s;
int e;
};
bool cmp(node x, node y)
{
return x.s < y.s || (x.s == y.s && x.e < y.e);
};
struct cmp2{
bool operator()(int x, int y)
{
return x > y;
};
};
class Solution {
public:
int minMeetingRooms(vector<vector<int>>& intervals) {
if(intervals.size() == 0)return 0;
vector<node> v;
for(int i = 0; i < intervals.size(); ++i)
{
node n;
n.s = intervals[i][0];
n.e = intervals[i][1];
v.push_back(n);
}
sort(v.begin(), v.end(), cmp);
priority_queue<int, vector<int>, cmp2> q;
q.push(v[0].e);
for(int i = 1; i < v.size(); ++i)
{
int e = q.top();
cout << e << endl;
if(e <= v[i].s)
{
q.pop();
q.push(v[i].e);
}
else
{
q.push(v[i].e);
}
}
return q.size();
}
};