-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm729.py
39 lines (31 loc) · 1.26 KB
/
m729.py
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
class MyCalendar:
def __init__(self):
self.bookings = []
def book(self, start: int, end: int) -> bool:
insertLocation = bisect_left(self.bookings, (start, end))
# end of schedule
if insertLocation >= len(self.bookings) :
if not self.bookings :
self.bookings.append((start, end))
return True
if start == self.bookings[-1][1] :
self.bookings[-1] = (self.bookings[-1][0], end)
return True
if start < self.bookings[-1][1] :
return False
self.bookings.append((start, end))
return True
if insertLocation and start < self.bookings[insertLocation - 1][1] :
return False
if start == self.bookings[insertLocation][0] :
return False
if end == self.bookings[insertLocation][0] :
self.bookings[insertLocation] = (start, self.bookings[insertLocation][1])
return True
if end > self.bookings[insertLocation][0] :
return False
self.bookings.insert(insertLocation, (start, end))
return True
# Your MyCalendar object will be instantiated and called as such:
# obj = MyCalendar()
# param_1 = obj.book(start,end)