Skip to content

Commit b951875

Browse files
author
Zhenchao Gan
authored
330. Patching Array
1 parent 28656b8 commit b951875

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

cpp/321-330/Patching Array.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
class Solution {
22
public:
33
int minPatches(vector<int>& nums, int n) {
4-
5-
sort(nums.begin(), nums.end());
6-
74
int i(0), res(0);
85
long miss(0);
96

10-
while(miss < n) {
11-
if(i < nums.size() && miss >= (nums[i] - 1) ) {
7+
while (miss < n) {
8+
if (i < nums.size() && miss >= (nums[i] - 1) ) {
129
miss += nums[i];
1310
i++;
1411
} else {
1512
res++;
1613
miss += (miss+1);
1714
}
1815
}
19-
2016
return res;
2117
}
22-
};
18+
};

0 commit comments

Comments
 (0)