-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaily101.cpp
More file actions
62 lines (51 loc) · 1.33 KB
/
Copy pathdaily101.cpp
File metadata and controls
62 lines (51 loc) · 1.33 KB
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
57
58
59
60
61
62
// Solution 1
class MyCalendar {
public:
MyCalendar()
: bookings_{} {}
bool book(int start, int end) {
auto booking = std::make_pair(start, end);
for (auto& b : bookings_) {
if (end <= b.first)
continue;
if (start >= b.second)
continue;
return false;
}
bookings_.push_back(booking);
return true;
}
private:
std::vector<std::pair<int, int>> bookings_;
};
/**
* Your MyCalendar object will be instantiated and called as such:
* MyCalendar* obj = new MyCalendar();
* bool param_1 = obj->book(start,end);
make matrix for start and end times?
keep track of existing start and ending times
*/
// Solution 2
char speedUp = [] {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
return 'z';
}();
class MyCalendar {
struct Node {
int start, end;
Node(int start, int end) : start(start), end(end) {}
bool operator<(const Node& other) const { return other.start >= end; }
};
set<Node> s;
public:
MyCalendar() {}
bool book(int start, int end) {
auto it = s.lower_bound({start, end});
if (it != s.end() && it->start < end)
return false;
s.insert({start, end});
return true;
}
};