← 返回 bytedance 的题目列表Coin Change
类型:online_judge
bytedance
You are given coins of different denominations and a total amount of money. 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.
Input:
coins: An integer array representing different denominations of coins.
amount: An integer representing the total amount.
Output:
The fewest number of coins that you need to make up the amount.
Example:
Input: coins = [1, 2, 5], amount = 11
Output: 3
Explanation: 11 = 5 + 5 + 1
Constraints:
1 <= coins.length <= 12
1 <= coins[i] <= 231 - 1
0 <= amount <= 104
Example
Input
[[1, 2, 5], 11]