[Oracle] LeetCode 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.
Solution
先按照左端点排序的话,如果一个区间的右端点比下一个区间的左端点大,那么显然得额外新增一个房间。
注意到 \(map\) 里的元素是排序的,所以我们可以对于每一个区间右端点 \(+1\), 左端点 \(-1\).
点击查看代码
class Solution {
private:
int ans=0;
map<int,int> mp;
public:
int minMeetingRooms(vector<vector<int>>& intervals) {
int n = intervals.size();
for(int i=0;i<n;i++){
mp[intervals[i][0]]+=1;
mp[intervals[i][1]]-=1;
}
int cur=0;
for(auto ele:mp){
cur+=ele.second;
ans=max(ans, cur);
}
return ans;
}
};
标签:map,int,Solution,II,区间,intervals,Rooms,端点,Oracle 来源: https://www.cnblogs.com/xinyu04/p/16600675.html