1109. 航班預訂統計

chhh31發表於2024-11-19

1109. 航班預訂統計

class Solution {
public:
    vector<int> corpFlightBookings(vector<vector<int>>& bookings, int n) {
        vector<int> sum(n,0);
        for(int i = 0;i < bookings.size();i ++)
        {
            int st = bookings[i][0] - 1,ed = bookings[i][1] - 1,num = bookings[i][2];
            sum[st] += num;
            if(ed + 1 < n)sum[ed + 1] -= num;
        }
        for(int i = 1;i < sum.size();i ++)
        {
            sum[i] += sum[i - 1];
        }
        
        return sum;
    }
};

相關文章