Created
January 21, 2019 05:54
-
-
Save kanrourou/32dad29d075a9d66a776895acd107af4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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