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)


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