-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLC0483.py
29 lines (23 loc) · 923 Bytes
/
LC0483.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
class MyCalendarTwo:
def __init__(self):
self.bookings = []
self.overlap_bookings = []
def book(self, start: int, end: int) -> bool:
for booking in self.overlap_bookings:
if self.does_overlap(booking[0], booking[1], start, end):
return False
for booking in self.bookings:
if self.does_overlap(booking[0], booking[1], start, end):
self.overlap_bookings.append(
self.get_overlapped(booking[0], booking[1], start, end)
)
self.bookings.append((start, end))
return True
def does_overlap(
self, start1: int, end1: int, start2: int, end2: int
) -> bool:
return max(start1, start2) < min(end1, end2)
def get_overlapped(
self, start1: int, end1: int, start2: int, end2: int
) -> tuple:
return max(start1, start2), min(end1, end2)