Python sweep line work with min heap

  • 0
    class Solution(object):
        def minMeetingRooms(self, intervals):
            intervals.sort(key = lambda x: x.start) 
            heap, ans = [], 0
            for interval in intervals:
                while heap and (heap[0]) <= interval.start:
                heapq.heappush(heap, interval.end)
                ans = max(ans, len(heap))
            return ans

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.