代码拉取完成,页面将自动刷新
bool cmp(const std::vector<int> &a, const std::vector<int> &b) {
return a[1] < b[1];
}
class Solution {
public:
bool carPooling(vector<vector<int>>& trips, int capacity) {
// Analog
sort(trips.begin(), trips.end(), cmp);
int len = trips.size();
if (len == 0) return true;
vector<int> seats(capacity, 0);
int f = 0, nowSeats = 0;
for (int i = 0; i < len; i++) {
for (int j = 0; j < capacity; j++) {
if (seats[j] && seats[j] <= trips[i][1])
seats[j] = 0, nowSeats--;
}
if (nowSeats + trips[i][0] <= capacity) {
int j = 0, t = nowSeats;
while (nowSeats - t < trips[i][0]) {
if (seats[j] == 0) {
seats[j] = trips[i][2];
nowSeats++;
}
j++;
}
}
else return false;
}
return true;
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。