/* * 330. Patching Array * 2016-7-9 by Mingyang * hehe */
public int minPatches(int[] nums, int n) { long miss = 1; int index = 0; int count = 0; while(miss <= n){ if(index<nums.length && nums[index] <= miss){ miss += nums[index++]; }else{ miss *= 2; count++; } } return count; }