Why this one runtime exceed limit?


  • 0
    S
    class Solution(object):
        def coinChange(self, coins, amount):
            """
            :type coins: List[int]
            :type amount: int
            :rtype: int
            """
            n = len(coins)
            maxCount = 1+int(amount*1.0/min(coins))
            
            dp = [0]
            for j in range(1, amount+1):
                dp += [maxCount]
                for i in range(n):
                    if j >= coins[i]:
                        dp[j] = min(dp[j], dp[j-coins[i]]+1)
            return dp[-1] if dp[-1]!= maxCount else -1
    

    why this one runtime exceed limit?


Log in to reply
 

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