LC 2952. 需要添加的硬币的最小数量

https://leetcode.cn/problems/minimum-number-of-coins-to-be-added/description/

题解 写的非常好,就是使用归纳法:

class Solution:
    def minimumAddedCoins(self, coins: List[int], target: int) -> int:
        coins.sort()
        ans, s, i = 0, 1, 0
        while s <= target:
            if i < len(coins) and coins[i] <= s:
                s += coins[i]
                i += 1
            else:
                s += s
                ans += 1
        return ans