4 lines Python DP solution


  • 1
    X
    class Solution(object):
        def combinationSum4(self, nums, target):
            dp = [1] + [0]*target
            for t in range(1, target+1):
                dp[t] = sum([dp[t-i] for i in nums if t-i >= 0])
            return dp[-1]
    

Log in to reply
 

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