My Calendar III LeetCode solution in Python

1
import bisect
2

3

4
class MyCalendarThree:
5

6
def __init__(self):
7
self.events = []
8

9
def book(self, start: int, end: int) -> int:
10
L, R = 1, 0
11
bisect.insort(self.events, (start, L))
12
bisect.insort(self.events, (end, R))
13
res = 0
14
cnt = 0
15
for _, state in self.events:
16
# if an interval starts, increase the counter
17
# othewise, decreas the counter
18
cnt += 1 if state == L else -1
19
res = max(res, cnt)
20
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0