from Queue import PriorityQueue class Solution(object): def minMeetingRooms(self, intervals): """ :type intervals: List[Interval] :rtype: int """ if not intervals: return 0 intervals = sorted(intervals, key = lambda a: a.start) # Sorted by start time. count = 1 available_rooms = PriorityQueue() first_room = intervals available_rooms.put((first_room.end, first_room.start)) for index in range(1, len(intervals)): meeting = intervals[index] soonest_available_room = available_rooms.get() if soonest_available_room <= meeting.start: available_rooms.put((meeting.end, meeting.start)) else: # If the room with the soonest finish time doesn't satisfy, # have to create a new room. count += 1 available_rooms.put(soonest_available_room) available_rooms.put((meeting.end, meeting.start)) return count
Python Simulation Solution with PriorityQueue
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.