难度:中等
类型:数组
题意:找到最少使用的会议室数,可以用上下车的思维来考虑。会议室的开始时间为上车,会议室的结束时间为下车,我们需要统计在车上的人的最大数量。按照时间的先后顺序排序,注意如果在同一个时刻既有上车又有下车的人,先下后上,腾出最大的空间。随意排序的时候加入了第二个关键字,就是为了防止上车的先算。
class Solution {
public:
int minMeetingRooms(vector<vector<int>>& intervals) {
vector<pair<int, int>> temp;
for(auto interval: intervals){
temp.push_back({interval[0], 1});
temp.push_back({interval[1], -1});
}
sort(temp.begin(), temp.end());
int cnt = 0, res = 0;
for(auto it: temp){
if(it.second > 0) cnt++;
else cnt--;
res = max(res, cnt);
}
return res;
}
};