Leetcode 330 Solution
This article provides solution to leetcode question 330 (patching-array)
Access this page by simply typing in "lcs 330" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/patching-array
Solution
class Solution {
public:
int minPatches(vector<int>& nums, int n) {
int64_t miss = 1;
int i = 0;
int res = 0;
while (miss <= n)
{
if (i < nums.size() && nums[i] <= miss)
miss += nums[i++];
else
res++, miss += miss;
}
return res;
}
};