Python Solution using priority queue but cannot pass some test cases


  • 0
    L

    My solution using priority queue cannot pass test case like [[9,10],[4,9],[4,17]]
    The result should be 2 but I returned 3, can anyone tell me how to fix this bug?
    Thanks so much!

    def minMeetingRooms(self, intervals):
        """
        :type intervals: List[Interval]
        :rtype: int
        """
        if intervals is None or len(intervals) == 0:
            return 0
            
        intervals.sort(key = lambda x : x.start)
        
        pq = []
        pq.append(intervals[0].end)
        for i in range(1, len(intervals)):
            if intervals[i].start >= pq[-1]:
                pq.pop()
            pq.append(intervals[i].end)
            
        return len(pq)

Log in to reply
 

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