Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- class Solution {
- public:
- int minPatches(std::vector<int>& nums, int n) {
- long miss = 1;
- int patches = 0;
- int i = 0;
- while (miss <= n) {
- if (i < nums.size() && nums[i] <= miss) {
- miss += nums[i++];
- } else {
- miss += miss;
- patches++;
- }
- }
- return patches;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement