1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// @Title: 按要求补齐数组 (Patching Array)
// @Author: 15816537946@163.com
// @Date: 2020-12-29 23:39:59
// @Runtime: 12 ms
// @Memory: 3.3 MB
func minPatches(nums []int, n int) (patches int) {
	for i, x := 0, 1; x <= n; {
		if i < len(nums) && nums[i] <= x {
			x += nums[i]
			i++
		} else {
			x *= 2
			patches++
		}
	}
	return
}