Skip to content

Commit

Permalink
Time: 957 ms (13.56%), Space: 86.6 MB (17.00%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed Nov 27, 2022
1 parent cff4af6 commit 981c7cd
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Solution {
public:
static const bool mySort(vector<int> &a, vector<int> &b) {
if (a[0] != b[0]) {
return a[0] < b[0];
}
return a[1] < b[1];
}

int maxEvents(vector<vector<int>>& events) {
sort(events.begin(), events.end(), mySort);

int n = events.size();
int ans = 0;
int i = 0;

multiset<int> s;
for (int d = 1; d < 100001; ++d) {
while (!s.empty() && *(s.begin()) < d) {
s.erase(s.begin());
}

while (i < n && events[i][0] == d) {
s.insert(events[i][1]);
i++;
}

if (s.size() > 0) {
ans++;
s.erase(s.begin());
}
}

return ans;

}
};

0 comments on commit 981c7cd

Please sign in to comment.