-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cpp
41 lines (36 loc) · 833 Bytes
/
Solution.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
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
class MyCalendarThree {
private:
// Line sweep, {time, count}.
std::map<int32_t, int32_t> calendar;
public:
MyCalendarThree() {}
int book(int startTime, int endTime) {
++calendar[startTime];
--calendar[endTime];
int32_t prefix{0};
int32_t k{0};
for (const auto [time, count] : calendar) {
prefix += count;
k = std::max(k, prefix);
}
return k;
}
};
/**
* Your MyCalendarThree object will be instantiated and called as such:
* MyCalendarThree* obj = new MyCalendarThree();
* int param_1 = obj->book(startTime,endTime);
*/