-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1353_leetcode
More file actions
31 lines (29 loc) · 859 Bytes
/
1353_leetcode
File metadata and controls
31 lines (29 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1353. Maximum Number of Events That Can Be Attended
t = O(nlogn)
class Solution {
public:
int maxEvents(vector<vector<int>>& events) {
sort(events.begin(), events.end());
priority_queue<int, vector<int>, greater<int>> minHeap;
int i = 0, n = events.size();
int day = 1, res = 0;
while (i < n || !minHeap.empty()) {
if (minHeap.empty()) {
day = events[i][0];
}
while (i < n && events[i][0] <= day) {
minHeap.push(events[i][1]);
i++;
}
while (!minHeap.empty() && minHeap.top() < day) {
minHeap.pop();
}
if (!minHeap.empty()) {
minHeap.pop();
res++;
day++;
}
}
return res;
}
};