class Solution(object):
def minPatches(self, nums, n):
"""
:type nums: List[int]
:type n: int
:rtype: int
"""
size=len(nums)
i,add, miss=0,0,1
while miss<=n:
if i<size and nums[i]<=miss:
miss+=nums[i]
i+=1
else:
miss+=miss
add+=1
def minPatches(self, nums, n):
"""
:type nums: List[int]
:type n: int
:rtype: int
"""
size=len(nums)
i,add, miss=0,0,1
while miss<=n:
if i<size and nums[i]<=miss:
miss+=nums[i]
i+=1
else:
miss+=miss
add+=1
return add
参考:https://leetcode.com/problems/patching-array/#/solutions