forked from kamyu104/LeetCode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeeting-rooms-ii.py
34 lines (29 loc) · 869 Bytes
/
meeting-rooms-ii.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Time: O(nlogn)
# Space: O(n)
# Definition for an interval.
# class Interval:
# def __init__(self, s=0, e=0):
# self.start = s
# self.end = e
class Solution:
# @param {Interval[]} intervals
# @return {integer}
def minMeetingRooms(self, intervals):
starts, ends = [], []
for i in intervals:
starts.append(i.start)
ends.append(i.end)
starts.sort()
ends.sort()
s, e = 0, 0
min_rooms, cnt_rooms = 0, 0
while s < len(starts):
if starts[s] < ends[e]:
cnt_rooms += 1 # Acquire a room.
# Update the min number of rooms.
min_rooms = max(min_rooms, cnt_rooms)
s += 1
else:
cnt_rooms -= 1 # Release a room.
e += 1
return min_rooms