Last active
June 6, 2019 04:57
-
-
Save athulmurali/a88fa9c7d8687d34d1ed357dc16b3c70 to your computer and use it in GitHub Desktop.
Meeting Rooms ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for an interval. | |
# class Interval: | |
# def __init__(self, s=0, e=0): | |
# self.start = s | |
# self.end = e | |
class Solution: | |
def minMeetingRooms(self, intervals: List[Interval]) -> int: | |
import heapq | |
heap = [] | |
max_rooms = 0 | |
intervals.sort(key=lambda x: x.start) | |
for ent in intervals: | |
heapq.heappush(heap, ent.end) | |
while heap and heap[0] <= ent.start: | |
heapq.heappop(heap) | |
max_rooms = max(len(heap),max_rooms) | |
return max_rooms | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment