leetcode

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

0900.cpp (340B)


1 class RLEIterator { 2 vector<int> &vec; 3 int idx = 0; 4 5 public: 6 RLEIterator(vector<int> &encoding) : vec(encoding) {} 7 8 int next(int n) { 9 while (idx < vec.size() && n > vec[idx]) 10 n -= vec[idx], idx += 2; 11 if (idx >= vec.size()) return -1; 12 vec[idx] -= n; 13 return vec[idx + 1]; 14 } 15 };