跳转至

航班预订统计⚓︎

Leetcode题目链接

描述⚓︎

详见中文题目链接

解答⚓︎

class Solution {
public:
    vector<int> corpFlightBookings(vector<vector<int>>& bookings, int n) {
        vector<int> counters(n, 0);

        for (const auto& booking : bookings) {
            counters[booking[0] - 1] += booking[2];
            if (booking[1] < n)
                counters[booking[1]] -= booking[2];
        }

        for (int i = 1; i < n; i++) {
            counters[i] += counters[i - 1];
        }

        return counters;
    }
};