Advertisement
nikunjsoni

900

Jul 26th, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. class RLEIterator {
  2. public:
  3.     int curInd;
  4.     vector<int> seq;
  5.     RLEIterator(vector<int>& A) {
  6.         seq = A;
  7.         curInd = 0;
  8.     }
  9.    
  10.     int next(int n) {
  11.         while(curInd < seq.size()){
  12.             if(seq[curInd]>=n){
  13.                 seq[curInd]-=n;
  14.                 return seq[curInd+1];
  15.             }else{
  16.                 n -= seq[curInd];
  17.                 curInd += 2;
  18.             }
  19.         }
  20.         return -1;
  21.     }
  22. };
  23.  
  24. /**
  25.  * Your RLEIterator object will be instantiated and called as such:
  26.  * RLEIterator* obj = new RLEIterator(encoding);
  27.  * int param_1 = obj->next(n);
  28.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement