1094. Car Pooling
https://leetcode.com/problems/car-pooling/description/
/*
* @lc app=leetcode id=1094 lang=cpp
*
* [1094] Car Pooling
*/
// @lc code=start
class Solution {
public:
bool carPooling(vector<vector<int>>& trips, int capacity) {
map<int, int> points;
for (const auto &t : trips) {
points[t[1]] += t[0];
points[t[2]] -= t[0];
}
int s = 0;
for (auto &p : points) {
s += p.second;
if (s > capacity) return false;
}
return true;
}
};
// @lc code=end
Last updated