Simple and fast python solution


  • 0
    W

    the variable 'need' is the maximum number of rooms needed. the room variable records the current number of rooms needed.

    class Solution(object):
        def minMeetingRooms(self, intervals):
            """
            :type intervals: List[Interval]
            :rtype: int
            """
            if (not intervals):
                return 0
    
            starting = {}
            ending = {}
            lst = []
            room = 0
            need = 0
            
            for item in intervals:
                if item.start in starting:
                    starting[item.start] += 1
                else:
                    starting[item.start] = 1
                    if item.start not in ending:
                        lst.append(item.start)
                if item.end in ending:
                    ending[item.end] += 1
                else:
                    ending[item.end] = 1
                    if item.end not in starting:
                        lst.append(item.end)
                        
            lst.sort()
                    
            for item in lst:
                if item in starting:
                    room += starting[item]
                if item in ending:
                    room -= ending[item]
                if room > need:
                    need = room
                
            return need

Log in to reply
 

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