Very short python solution, sort + O(n)


  • 0
    A

    Suppose start and end are events. Only need to count events, no need to calculate segments overlapping

    class Solution(object):
       def minMeetingRooms(self, intervals):
           if len(intervals) == 0:
               return 0
           ary = []
           for i in intervals:
               ary.append((i.start, 1))
               ary.append((i.end, -1))
           ary.sort()
           sum, res = 0, 0
           for i in ary:
               sum += i[1]
               res = max(sum, res)
           return res
    

Log in to reply
 

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