Python solution 76ms


  • 0
    A
    class Solution:
    # @param {Interval[]} intervals
    # @return {integer}
    def minMeetingRooms(self, intervals):
        if len(intervals) < 2:
            return len(intervals)
    
        intervals.sort(key = lambda x: x.start)
        rooms = [intervals[0]]
        for i in xrange(1, len(intervals)):
            flag = False
            for r in rooms:
                # use current room
                if intervals[i].start >= r.end:
                    r.end = max(r.end, intervals[i].end)
                    flag = True
                    break
            # need new room
            if not flag:
                rooms.append(intervals[i])
                    
        return len(rooms)

Log in to reply
 

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