class Solution:
def mostBooked(self, n: int, meetings: List[List[int]]) -> int:
meetings.sort()
heap=[]
counter=defaultdict(int)
available_rooms=[]
for i in range(n):
heappush(available_rooms,i)
cnt=0
for i in range(len(meetings)):
while heap and heap[0][0]<=meetings[i][0]:
h=heappop(heap)
heappush(available_rooms,h[1])
if available_rooms:
room=heappop(available_rooms)
heappush(heap,(meetings[i][1],room))
counter[room]+=1
else:
h=heappop(heap)
counter[h[1]]+=1
if h[0]>meetings[i][0]:
diff=h[0]-meetings[i][0]
meetings[i][1]+=diff
# print(h[0],h[1])
heappush(heap,(meetings[i][1],h[1]))
ans=0
for k in list(counter.keys()):
if counter[k]>counter[ans]:
ans=k
return ans
这里要维持两个heap