Python, 120ms, o(n^2) ,straight forward solution.


  • 0
    I

    The idea is simple.

    use a vector to keep every meetings room last time.

    def minMeetingRooms(self, intervals):
        intervals.sort(cmp = lambda x,y:x.end - y.end if x.end != y.end else x.start - y.start)
        n = len(intervals)
        if n <= 0:
            return n
        last = []
        last.append(intervals[0].end)
        for i in xrange(1,n):
            j = len(last) - 1
            while j >= 0 and intervals[i].start < last[j]:
                j -= 1
            if j >= 0:
                last.pop(j)
            last.append(intervals[i].end)
        return len(last)

Log in to reply
 

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