跳转至

拼车⚓︎

Leetcode题目链接

描述⚓︎

详见中文题目链接

解答⚓︎

class Solution {
public:
    bool carPooling(vector<vector<int>>& trips, int capacity) {
        int n = trips.size();
        vector<int> count(1001);
        for (auto& trip : trips) {
            int num = trip[0], from = trip[1], to = trip[2];
            count[from] += num;
            count[to] -= num;
        }

        int sum = 0;
        for (int element : count) {
            sum += element;
            if (sum > capacity) return false;
        }

        return true;
    }
};