We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent da9c7d9 commit aa2d2d0Copy full SHA for aa2d2d0
C++/my-calendar-i.cpp
@@ -0,0 +1,32 @@
1
+// Time: O(nlogn)
2
+// Space: O(n)
3
+
4
+class MyCalendar {
5
+public:
6
+ MyCalendar() {
7
8
+ }
9
10
+ bool book(int s, int e) {
11
+ auto next = books_.lower_bound(s);
12
+ if (next != books_.end() && next->first < e) {
13
+ return false;
14
15
+ if (next != books_.begin() && s < (--next)->second) {
16
17
18
+ books_[s] = e;
19
+ return true;
20
21
22
+private:
23
+ map<int, int> books_;
24
25
+};
26
27
+/**
28
+ * Your MyCalendar object will be instantiated and called as such:
29
+ * MyCalendar obj = new MyCalendar();
30
+ * bool param_1 = obj.book(start,end);
31
+ */
32
0 commit comments