Skip to content

Commit 338cd2c

Browse files
authored
Update 330-patching-array.js
1 parent 0a92c98 commit 338cd2c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

330-patching-array.js

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} n
4+
* @return {number}
5+
*/
6+
const minPatches = function(nums, n) {
7+
let sum = 1, res = 0, i = 0
8+
while(sum <= n) {
9+
if(i < nums.length && nums[i] <= sum) {
10+
sum += nums[i]
11+
i++
12+
} else {
13+
res++
14+
sum *= 2
15+
}
16+
}
17+
18+
return res
19+
};
20+
21+
// another
22+
123
/**
224
* @param {number[]} nums
325
* @param {number} n

0 commit comments

Comments
 (0)