My Calendar III LeetCode solution in Python
1import bisect234class MyCalendarThree:56def __init__(self):7self.events = []89def book(self, start: int, end: int) -> int:10L, R = 1, 011bisect.insort(self.events, (start, L))12bisect.insort(self.events, (end, R))13res = 014cnt = 015for _, state in self.events:16# if an interval starts, increase the counter17# othewise, decreas the counter18cnt += 1 if state == L else -119res = max(res, cnt)20return res