1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/go/patching-array.go
Matej Focko 898040fcad
go: add «330. Patching Array»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-06-16 11:46:41 +02:00

19 lines
256 B
Go

package main
func minPatches(nums []int, n int) int {
missing := 1
patches := 0
i := 0
for missing <= n {
if i < len(nums) && nums[i] <= missing {
missing += nums[i]
i++
} else {
missing += missing
patches++
}
}
return patches
}