_Gia_Cat_Luong_
Senior Member
Gặp bài hard là phải trồi lên
Python:
class Solution:
def minPatches(self, nums: List[int], n: int) -> int:
expect = 1
nums.reverse()
count = 0
while expect <= n:
if nums and expect >= nums[-1]:
expect += nums[-1]
nums.pop()
else:
expect *= 2
count += 1
# print(expect)
return count