leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0900.cpp (340B)
0 class RLEIterator { 1 vector<int> &vec; 2 int idx = 0; 3 4 public: 5 RLEIterator(vector<int> &encoding) : vec(encoding) {} 6 7 int next(int n) { 8 while (idx < vec.size() && n > vec[idx]) 9 n -= vec[idx], idx += 2; 10 if (idx >= vec.size()) return -1; 11 vec[idx] -= n; 12 return vec[idx + 1]; 13 } 14 };