[LeetCode] Meeting Rooms II

253. Meeting Rooms II

Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public:
int minMeetingRooms(vector<vector<int>>& arr) {
sort(arr.begin(), arr.end());
int res = 1;
priority_queue<int, vector<int>, greater<>> q;
for(auto it = arr.begin(); it != end(arr);) {
while(!q.empty() && q.top() <= it->front()) q.pop();
int time = it->front();
while(it != end(arr) && it->front() == time) {
q.push(it->back());
it = next(it);
}
res = max(res, (int)q.size());
}
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2021/05/03/PS/LeetCode/meeting-rooms-ii/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.