Few Lines DP Solution in Python


  • 0
    U
    class Solution(object):
        def combinationSum4(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: int
            """
            maps = {i: 0 for i in range(target + 1)}
            maps[0] = 1
            i = 1
            while i <= target:
                for num in nums:
                    if num <= i:
                        maps[i] += maps[i - num]
                i += 1
                        
            return maps[target]
    

  • 0
    K

    Why do you use hash instead of an array?


Log in to reply
 

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