Skip to content

Instantly share code, notes, and snippets.

@kanrourou
Created January 21, 2019 05:54
Show Gist options
  • Save kanrourou/32dad29d075a9d66a776895acd107af4 to your computer and use it in GitHub Desktop.
Save kanrourou/32dad29d075a9d66a776895acd107af4 to your computer and use it in GitHub Desktop.
/**
* Definition for an interval.
* struct Interval {
* int start;
* int end;
* Interval() : start(0), end(0) {}
* Interval(int s, int e) : start(s), end(e) {}
* };
*/
class Solution {
public:
int minMeetingRooms(vector<Interval>& intervals) {
vector<pair<int, int>> events;
for(auto& interval : intervals)
{
events.push_back({interval.start, 1});
events.push_back({interval.end, -1});
}
sort(events.begin(), events.end());
int depth = 0, currD = 0;
for(auto& event : events)
{
currD += event.second;
depth = max(depth, currD);
}
return depth;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment