AC python DP solution


  • 0
    L
    class Solution(object):
        def combinationSum4(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: int
            """
            dp = [1]
            nums.sort()
            for i in xrange(1, target+1):
                buf = 0
                for num in nums:
                    if num > i:
                        break
                    buf += dp[i-num]
                dp.append(buf)
            return dp[-1]
    

Log in to reply
 

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