898040fcad
Signed-off-by: Matej Focko <me@mfocko.xyz>
19 lines
256 B
Go
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
|
|
}
|