Python | Leetcode Python题解之第377题组合总和IV

题目:

Python | Leetcode Python题解之第377题组合总和IV_第1张图片

题解:

class Solution:
    def combinationSum4(self, nums: List[int], target: int) -> int:
        dp = [1] + [0] * target
        for i in range(1, target + 1):
            for num in nums:
                if num <= i:
                    dp[i] += dp[i - num]
        
        return dp[target]

你可能感兴趣的:(分享,Python,Leetcode,题解)