class Solution {
public:
bool carPooling(vector<vector<int>>& trips, int capacity) {
int to_max = 0;
for (const auto& trip: trips) {
to_max = max(to_max, trip[2]);
}
vector<int> diff(to_max + 1);
for (const auto& trip: trips) {
diff[trip[1]] += trip[0];
diff[trip[2]] -= trip[0];
}
int count = 0;
for (int i = 0; i <= to_max; ++i) {
count += diff[i];
if (count > capacity) {
return false;
}
}
return true;
}
};
05-24
282
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-21
675
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交