Coin Change
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return 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.
Coin Change
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return 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.
Example 1
Input: coins = [1,2,5], amount = 11 Output: 3
Example 2
Input: coins = [2], amount = 3 Output: -1
Show hint
Use DP: dp[i] = minimum coins needed for amount i. For each coin, update dp[i] = min(dp[i], dp[i-coin] + 1) if i >= coin.
Sign in to submit, save progress and mark problems as solved. You can still run your code.
Loading editor...
[1,2,5]
11
3