729. My Calendar I
https://leetcode.com/problems/my-calendar-i/
Python
For the book
method:
- Time: O(logN) # N: The booked schedule
- Space: O(1) # If the (start, end) pair accepted, each time took O(1)
class MyCalendar:
def __init__(self):
self.booked = []
def book(self, start: int, end: int) -> bool:
for i in range(len(self.booked)):
s_start, s_end = self.booked[i]
if start >= s_end:
continue
if end > s_start:
return False
self.booked.insert(i, (start, end))
return True
self.booked.append((start, end))
return True