Coin Change
Problem statement
You have an unlimited supply of each denomination in coins. Return the smallest number of coins whose total is amount.
Return -1 if no combination reaches the amount. Making amount 0 requires no coins.
Function
coinChange(coins: int[], amount: int) → intExamples
Example 1
coins = [1,2,5]amount = 11return = 3Use 5 + 5 + 1.
Example 2
coins = [2]amount = 3return = -1A sum of coins valued 2 cannot be odd.
Example 3
coins = [1]amount = 0return = 0The empty selection has total zero.
Constraints
1 <= coins.length <= 12.1 <= coins[i] <= 2^31 - 1.0 <= amount <= 10^4.