Ways to make change
Mediumdynamic programmingarray
Return how many different ways coins can make amount (each coin may repeat). Order doesn't matter: 1+2 and 2+1 are the same way.
Example 1
Input: amount = 5, coins = [1,2,5] Output: 4
5, 2+2+1, 2+1+1+1, 1+1+1+1+1.
Example 2
Input: amount = 3, coins = [2] Output: 0
Constraints
- 0 ≤ amount ≤ 1000
- 1 ≤ coins.length ≤ 100
- Coins are distinct, 1 ≤ coins[i] ≤ 1000
- The answer fits in 64 bits
Submit checks your solution against 9 tests, including hidden ones.
/**
* @param {int} amount
* @param {int[]} coins
* @return {long}
*/
function change(amount, coins) {
}