leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1109.cpp (438B)


      1 class Solution {
      2   public:
      3     vector<int> corpFlightBookings(const vector<vector<int>> &bookings, int n) {
      4         vector<int> res(n + 1, 0);
      5 
      6         for (const auto &booking : bookings) {
      7             res[booking[0] - 1] += booking[2];
      8             res[booking[1]] -= booking[2];
      9         }
     10 
     11         for (int i = 0, acc = 0; i < n; i++) {
     12             res[i] = acc += res[i];
     13         }
     14 
     15         res.resize(n);
     16         return res;
     17     }
     18 };