Coin Change II
Problem statement
You have an unlimited supply of each distinct denomination in coins. Count the combinations that sum to amount.
Order does not distinguish combinations: using coins 1,2,2 is the same combination as using 2,1,2. Return 0 when no combination exists. Amount 0 has one combination, the empty selection.
The requested count fits in a signed 32-bit integer.
Function
change(amount: int, coins: int[]) → intExamples
Example 1
amount = 5coins = [1,2,5]return = 4The combinations are [5], [2,2,1], [2,1,1,1], and [1,1,1,1,1].
Example 2
amount = 3coins = [2]return = 0No combination of denomination 2 reaches an odd amount.
Example 3
amount = 10coins = [10]return = 1Only one coin of denomination 10 is needed.
Constraints
1 <= coins.length <= 300.- All denominations are distinct, with
1 <= coins[i] <= 5000. 0 <= amount <= 5000.- The answer is at most
2^31 - 1.