My Calendar I
Implement aMyCalendar
class to store your events. A new event can be added if adding the event will not cause a double booking.
Your class will have the method,book(int start, int end)
. Formally, this represents a booking on the half open interval[start, end)
, the range of real numbersx
such thatstart <= x < end
.
Adouble bookinghappens when two events have some non-empty intersection (ie., there is some time that is common to both events.)
For each call to the methodMyCalendar.book
, returntrue
if the event can be added to the calendar successfully without causing a double booking. Otherwise, returnfalse
and do not add the event to the calendar.
Your class will be called like this:
MyCalendar cal = new MyCalendar();
MyCalendar.book(start, end)
Example
Note:
The number of calls to MyCalendar.book
per test case will be at most1000
.
In calls toMyCalendar.book(start, end)
,start
andend
are integers in the range[0, 10^9]
.
Note
key: start, value: end
需要满足 2 <= 10, 20 <= 100
Code
Last updated