Car Pooling LeetCode solution in C++

1
class Solution {
2
typedef pair<int, int> pd;
3

4
public:
5
bool carPooling(vector<vector<int>> &trips, int capacity) {
6
int seat = 0;
7
priority_queue<pd, vector<pd>, greater<pd>> pq;
8
for (auto it : trips) {
9
pq.push({it[1], +it[0]});
10
pq.push({it[2], -it[0]});
11
}
12
while (!pq.empty()) {
13
// cout<<pq.top().first<<" "<<pq.top().second<<endl;
14
// cout<<"seat-"<<seat<<endl;
15
seat += pq.top().second;
16
if (seat > capacity) return false;
17
pq.pop();
18
}
19
return true;
20
}
21
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0