1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class Solution { public int minPatches(int[] nums, int n) { int minAdd = 0; int i = 0; long start = 1; while (start - 1 < n) { if (i < nums.length && nums[i] <= start) { start += nums[i]; i++; } else { start += start; minAdd++; } }
return minAdd; } }
|