C语言 | Leetcode C语言题解之第330题按要求补齐数组
题目:
题解:
int minPatches(int* nums, int numsSize, int n) {int patches = 0;long long x = 1;int index = 0;while (x <= n) {if (index < numsSize && nums[index] <= x) {x += nums[index];index++;} else {x <<= 1;patches++;}}return patches;
}