330. Patching Array
题目链接:
想了半天没想出来,参考discussion里的解法:
public class Solution { public int minPatches(int[] nums, int n) { int i = 0, res = 0; long miss = 1; while(miss <= n) { if(i < nums.length && nums[i] <= miss) { miss += nums[i++]; } else { miss *= 2; res++; } } return res; }}