-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxEvents.py
More file actions
30 lines (26 loc) · 841 Bytes
/
maxEvents.py
File metadata and controls
30 lines (26 loc) · 841 Bytes
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
30
import heapq
class Solution:
def maxEvents(self, events: List[List[int]]) -> int:
if not events:
return 0
events.sort(key=lambda x:x[0])
curr_day=events[0][0]
counter=0
i=0
start=[]
while i<len(events):
while i<len(events) and events[i][0]==curr_day:
heappush(start, events[i][1])
i+=1
heappop(start)
counter+=1
curr_day+=1
while start and start[0]<curr_day:
heappop(start)
if i<len(events) and not start:
curr_day=events[i][0]
while start:
if heappop(start)>=curr_day:
curr_day+=1
counter+=1
return counter