-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_26.py
25 lines (22 loc) · 847 Bytes
/
Day_26.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
class MyCalendarTwo(object):
def __init__(self):
self.bookings=[]
def book(self, start, end):
for prevStart , prevEnd in self.bookings:
if start < prevEnd and end > prevStart:
newStart = max(prevStart, start)
newEnd = min(prevEnd , end)
if self.check(newStart , newEnd):
return False
self.bookings.append((start , end))
return True
def check(self , start ,end):
overlapping = 0
for prevStart , prevEnd in self.bookings :
if prevStart < end and prevEnd > start:
overlapping+=1
if overlapping==2:
return True
# Your MyCalendarTwo object will be instantiated and called as such:
# obj = MyCalendarTwo()
# param_1 = obj.book(start,end)