package leetcode;

/**
 * https://leetcode.com/problems/patching-array/
 */
public class Problem330 {
    public int minPatches(int[] nums, int n) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem330 prob = new Problem330();
        System.out.println(prob.minPatches(new int[]{1, 3}, 6)); // 1
        System.out.println(prob.minPatches(new int[]{1, 5, 10}, 20)); // 2
        System.out.println(prob.minPatches(new int[]{1, 2, 2}, 5)); // 0
    }
}

@@ -154,38 +154,50 @@
     
-// TODO%0A        return
+long sum = 0;%0A        int nPatch =
  0;%0A    
 %7D%0A%0A 
@@ -196,317 +196,334 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem330 prob = new Problem330();%0A        System.out.println(prob.minPatches(new int%5B%5D%7B1, 3%7D, 6)); // 1%0A        System.out.println(prob.minPatches(new int%5B%5D%7B1, 5, 10%7D, 20)); // 2%0A        System.out.println(prob.minPatches(new int%5B%5D%7B1, 2, 2%7D, 5)); // 0
+int index = 0;%0A        while (sum %3C n) %7B%0A            long patch = sum + 1;%0A            if (index %3E= nums.length %7C%7C patch %3C nums%5Bindex%5D) %7B%0A                nPatch++;%0A                sum += patch;%0A            %7D else %7B%0A                sum += nums%5Bindex%5D;%0A                index++;%0A            %7D%0A        %7D%0A        return nPatch;
 %0A   

Solve problem 330