leetcode

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

1094.cpp (470B)


      1 class Solution {
      2   public:
      3     bool carPooling(const vector<vector<int>> &trips, int capacity) const {
      4         static int count[1001];
      5         memset(count, 0x00, sizeof(count));
      6 
      7         for (const auto &trip : trips) {
      8             count[trip[1]] += trip[0];
      9             count[trip[2]] -= trip[0];
     10         }
     11 
     12         for (int i = 0; i < 1001; i++) {
     13             capacity -= count[i];
     14             if (capacity < 0) return false;
     15         }
     16 
     17         return true;
     18     }
     19 };