Python dp easily understanding


  • 0
    class Solution(object):
        def combinationSum4(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: int
            """
            dp = [0] * (target+1)
            nums.sort() 
            dp[0] = 1
            for i in range(1, target + 1):
                for j in range(len(nums)):
                    if i - nums[j] >= 0:
                        dp[i] += dp[i - nums[j]]       
            return dp[target]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.