You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.
classSolution(object):defcoinChange(self,coins,amount):""" :type coins: List[int] :type amount: int :rtype: int """# dp[i]: the least step needed to reach i dollars# dp[i+coin[j]] = min(dp[i]+1,dp[i+coin[j]])# dp[0] = 0dp=[0]+[0x7ffffffe]*(amount)foriinrange(amount+1):forjincoins:ifi+j<=amount:dp[i+j]=min(dp[i]+1,dp[i+j])returndp[amount]ifdp[amount]!=0x7ffffffeelse-1