Участник:Alexander Denisenko/patching array

Материал из DISCOPAL
Перейти к: навигация, поиск
class Solution(object):
    def minPatches(self, nums, n):
        nums.append(n + 1)
 
        diff = 0
        target = 1
        i = 0
 
        while target <= n:
            if nums[i] <= target:
                target += nums[i]
                i += 1
 
            elif nums[i] > target:
                diff += 1
                target *= 2
 
 
        return diff