0
点赞
收藏
分享

微信扫一扫

(回溯) LeetCode 77. 组合

书坊尚 2024-08-11 阅读 36

题目:

题解:

class Solution:
    def minPatches(self, nums: List[int], n: int) -> int:
        patches, x = 0, 1
        length, index = len(nums), 0

        while x <= n:
            if index < length and nums[index] <= x:
                x += nums[index]
                index += 1
            else:
                x <<= 1
                patches += 1
        
        return patches
举报

相关推荐

0 条评论