mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 253.cpp
This commit is contained in:
parent
63e2720fe7
commit
f822d5f73e
34
LeetCode-CN/253.cpp
Normal file
34
LeetCode-CN/253.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int minMeetingRooms(vector<vector<int>>& intervals) {
|
||||||
|
vector<int> starts, ends;
|
||||||
|
for (auto& vec : intervals) {
|
||||||
|
starts.push_back(vec[0]);
|
||||||
|
ends.push_back(vec[1]);
|
||||||
|
}
|
||||||
|
sort(starts.begin(), starts.end());
|
||||||
|
sort(ends.begin(), ends.end());
|
||||||
|
|
||||||
|
int needRoom = 0;
|
||||||
|
int maxRoom = 0;
|
||||||
|
for (int i = 0, j = 0; i < starts.size() && j < ends.size();) {
|
||||||
|
if (starts[i] < ends[j]) {
|
||||||
|
needRoom++;
|
||||||
|
maxRoom = max(maxRoom, needRoom);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (starts[i] > ends[j]) {
|
||||||
|
needRoom--;
|
||||||
|
j++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxRoom;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user