Simple and fast python solution

  • 0

    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
                    starting[item.start] = 1
                    if item.start not in ending:
                if item.end in ending:
                    ending[item.end] += 1
                    ending[item.end] = 1
                    if item.end not in starting:
            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.