Skip to content

Commit

Permalink
Add rough Line Sweep implementation for 253
Browse files Browse the repository at this point in the history
Seems to perform worse
  • Loading branch information
euchangxian committed Dec 18, 2024
1 parent f2a2b77 commit 6a17b2f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions C++/0253-MeetingRoomsTwo/Solution.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <vector>

Expand All @@ -20,4 +21,25 @@ class Solution {

return minHeap.size();
}

int minMeetingRoomsSweep(std::vector<std::vector<int>>& intervals) {
// line sweep version: find the maximum number of intersections between
// points.
std::map<int, int> events;
for (const auto& interval : intervals) {
const int start = interval[0];
const int incEnd = interval[1];

++events[start];
--events[incEnd];
}

int maxSum = 0;
int sum = 0;
for (const auto [time, count] : events) {
sum += count;
maxSum = std::max(maxSum, sum);
}
return maxSum;
}
};

0 comments on commit 6a17b2f

Please sign in to comment.