package leetcode;

/**
 * https://leetcode.com/problems/rle-iterator/
 */
public class Problem900 {
    private static class RLEIterator {
        public RLEIterator(int[] A) {
        }

        public int next(int n) {
            // TODO
            return 0;
        }
    }

    public static void main(String[] args) {
        RLEIterator iterator = new RLEIterator(new int[]{3, 8, 0, 9, 2, 5});
        System.out.println(iterator.next(2)); // 8
        System.out.println(iterator.next(1)); // 8
        System.out.println(iterator.next(1)); // 5
        System.out.println(iterator.next(2)); // -1
    }
}

@@ -132,16 +132,75 @@
 rator %7B%0A
+        private final int%5B%5D a;%0A        private int index;%0A%0A
         
@@ -225,24 +225,43 @@
 (int%5B%5D A) %7B%0A
+            a = A;%0A
         %7D%0A%0A 
@@ -308,16 +308,37 @@
     
-// TODO%0A
+if (index %3E= a.length) %7B%0A    
     
@@ -356,11 +356,16 @@
 urn 
-0;%0A
+-1;%0A    
     
@@ -378,337 +378,857 @@
     
+  
-%7D%0A%0A
+  
     
-public static void main(String%5B%5D args) %7B%0A        RLEIterator iterator = new RLEIterator(new int%5B%5D%7B3, 8, 0, 9, 2, 5%7D);%0A        System.out.println(iterator.next(2)); // 8%0A        System.out.println(iterator.next(1)); // 8%0A        System.out.println(iterator.next(1)); // 5%0A        System.out.println(iterator.next(2)); // -1
+int value = a%5Bindex + 1%5D;%0A            n -= a%5Bindex%5D;%0A            if (n %3C 0) %7B%0A                a%5Bindex%5D = n * -1;%0A            %7D else if (n == 0) %7B%0A                a%5Bindex%5D = 0;%0A                index += 2;%0A            %7D else %7B%0A                a%5Bindex%5D = 0;%0A                while (n %3E= 0) %7B%0A                    index += 2;%0A                    if (index %3E= a.length) %7B%0A                        return -1;%0A                    %7D%0A                    n -= a%5Bindex%5D;%0A                    value = a%5Bindex + 1%5D;%0A                    if (n %3C 0) %7B%0A                        a%5Bindex%5D = n * -1;%0A                        break;%0A                    %7D else if (n == 0) %7B%0A                        a%5Bindex%5D = 0;%0A                        index += 2;%0A                        break;%0A                    %7D%0A                %7D%0A            %7D%0A            return value;%0A        %7D
 %0A   

Solve problem 900