Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 807 Bytes

253. Meeting Rooms II.md

File metadata and controls

41 lines (35 loc) · 807 Bytes
class Solution {
public:
    int minMeetingRooms(vector<vector<int>>& intervals) {
        map<int, int> m;
        for (auto a : intervals) {
            ++m[a[0]];
            --m[a[1]];
        }
        int rooms = 0, res = 0;
        for (auto it : m) {
            res = max(res, rooms += it.second);
        }
        return res;
    }
};
class Solution {
public:
int minMeetingRooms(vector& intervals) {
		map<int, int> mp; // key: time; val: +1 if start, -1 if end
    for(int i=0; i< intervals.size(); i++) {
        mp[intervals[i].start] ++;
        mp[intervals[i].end] --;
    }
    
    int cnt = 0, maxCnt = 0;
    for(auto it = mp.begin(); it != mp.end(); it++) {
        cnt += it->second;
        maxCnt = max( cnt, maxCnt);
    }
    
    return maxCnt;
}
};