카테고리 없음
[C++] Min Heap <int>
focalpoint
2024. 2. 3. 04:08
https://leetcode.com/problems/meeting-rooms-ii/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution {
public:
int minMeetingRooms(vector<vector<int>>& intervals) {
sort(intervals.begin(), intervals.end());
priority_queue<int, vector<int>, greater<int>> pq;
int ret = 0;
for (vector<int>& interval : intervals) {
int s = interval[0], e = interval[1];
while (!pq.empty() and pq.top() <= s) {
pq.pop();
}
pq.push(e);
ret = max(ret, int(pq.size()));
}
return ret;
}
};