forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main4.cpp
55 lines (43 loc) · 1.21 KB
/
main4.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
/// Source : https://leetcode.com/problems/meeting-rooms-ii/description/
/// Author : liuyubobobo
/// Time : 2018-09-10
#include <iostream>
#include <vector>
using namespace std;
/// Dealing with start time and end time seperately
/// make start time and end time in a pair structure
/// and deal with them in one single vector:)
///
/// Time Complexity: O(nlogn)
/// Space Complexity: O(n)
/// 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) {
vector<pair<int, char>> timepoints;
for(const Interval& interval: intervals){
timepoints.push_back(make_pair(interval.start, 's'));
timepoints.push_back(make_pair(interval.end, 'e'));
}
sort(timepoints.begin(), timepoints.end());
int res = 0;
int cur = 0;
for(const pair<int, char>& p: timepoints)
if(p.second == 's'){
cur ++;
res = max(res, cur);
}
else
cur --;
return res;
}
};
int main() {
return 0;
}