1353. Maximum Number of Events That Can Be Attended (Medium) - TengnanYao/daily_leetcode GitHub Wiki
class Solution:
def maxEvents(self, events: List[List[int]]) -> int:
events.sort()
result = 0
heap = []
j = 0
for i in range(1, 100001):
while j < len(events) and events[j][0] <= i:
heapq.heappush(heap, events[j][1])
j += 1
while heap and heap[0] < i:
heapq.heappop(heap)
if heap:
result += 1
heapq.heappop(heap)
return result