We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b05d7ee commit ba25d86Copy full SHA for ba25d86
patch_array.cpp
@@ -0,0 +1,24 @@
1
+class Solution {
2
+public:
3
+ int minPatches(vector<int>& nums, int n) {
4
+ if (n == 0) return 0;
5
+ int num = nums.size();
6
+ long reach = 0;
7
+ int patch = 0;
8
+ for (int i = 0; i < num; ){
9
+ while (nums[i] > reach + 1){
10
+ reach += (reach + 1);
11
+ ++patch;
12
+ if (reach >= n) return patch;
13
+ }
14
+ reach += nums[i];
15
16
+ ++i;
17
18
+ while (reach < n){
19
20
21
22
+ return patch;
23
24
+};
0 commit comments