Book Events without Overlapping Time. Implement MyCalendar, initially empty. book(startTime,endTime) tries to reserve the half-open real interval [startTime,endTime).
### Problem
Implement MyCalendar, initially empty. book(startTime,endTime) tries to reserve the half-open real interval [startTime,endTime). Return true and store it only if it shares no moment with an existing reservation; otherwise return false without changing the calendar.
```cpp
class MyCalendar {
public:
MyCalendar();
bool book(int startTime, int endTime);
};
```
### Examples
**Example 1:**
```text
MyCalendar(); book(3,8); book(8,12); book(7,9)
Returns: [true,true,false]
Explanation: Touching at 8 is allowed, but [7,9) overlaps both reservations.
```
**Example 2:**
```text
MyCalendar(); book(1,5); book(2,4); book(5,6)
Returns: [true,false,true]
Explanation: Rejected reservations are never inserted.
```
### Constraints
- Endpoints obey 0 <= startTime < endTime <= 1000000000.
- There are at most 1000 book calls.
### Contract considerations
Keep the constructor and bool book method.
```hint Read the boundary condition
Which neighboring reservations can overlap a new sorted interval?
```
### Boundary reminders
Keep the constructor and bool book method.
Overview: Book Events without Overlapping Time. Implement MyCalendar, initially empty. book(startTime,endTime) tries to reserve the half-open real interval [startTime,endTime).
Implement MyCalendar, initially empty. book(startTime,endTime) tries to reserve the half-open real interval [startTime,endTime). Return true and store it only if it shares no moment with an existing reservation; otherwise return false without changing the calendar.
class MyCalendar {
public:
MyCalendar();
bool book(int startTime, int endTime);
};
Examples
Example 1:
MyCalendar(); book(3,8); book(8,12); book(7,9)
Returns: [true,true,false]
Explanation: Touching at 8 is allowed, but [7,9) overlaps both reservations.
Example 2:
MyCalendar(); book(1,5); book(2,4); book(5,6)
Returns: [true,false,true]
Explanation: Rejected reservations are never inserted.