My python solution


  • 0
    H
    class Solution(object):
        def combinationSum4(self, nums, target):
            nums=sorted(nums)
            i=0
            dp=[]
            while(i<=target):
                dp.append(0)
                i+=1
            n=i-1
            for i in range(len(nums)):
                if nums[i]>n:
                    break
                dp[nums[i]]=1
            for i in range(len(dp)):
                sum=0
                for j in range(len(nums)):
                    if(nums[j]<i):
                        sum+=dp[i-nums[j]]
                    else:
                        break
                dp[i]+=sum
            return dp[target]
    

Log in to reply
 

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