253. Meeting Rooms II
https://leetcode.com/problems/meeting-rooms-ii/description/
Thoughts
Code
class Solution {
public:
int minMeetingRooms(vector<vector<int>>& intervals) {
vector<vector<int>> ts;
for (const auto &interval : intervals) {
ts.push_back({interval[0], 1});
ts.push_back({interval[1], -1});
}
sort(ts.begin(), ts.end(), [](const auto &a, const auto &b) {
return a[0] == b[0] ? a[1] < b[1] : a[0] < b[0];
});
int sum = 0, res = 0;
for (const auto &t : ts) {
sum += t[1];
res = max(res, sum);
}
return res;
}
};Analysis
Last updated