Coin Change II

You are given coins of different denominations and a total amount of money amount. Write a function to compute the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0.

You may assume that you have an infinite number of each kind of coin.

Input

  • coins: A list of the coins and their denominations.
  • amount: The target amount

Output

The number of combinations that make up that amount.

Examples

Example 1:

Input:

1coins = [1, 2, 5]
2amount = 11

Output: 4

Explanation:

There are four ways to make up the amount:

  • 5 = 5
  • 5 = 2 + 2 + 1
  • 5 = 2 + 1 + 1 + 1
  • 5 = 1 + 1 + 1 + 1 + 1

Example 2:

Input:

1coins = [2]
2amount = 3

Output: 0

Explanation:

The amount of 3 cannot be made up with just coins of 2.

Constraints

  • 1 <= len(coins) <= 300
  • 1 <= amount <= 5000
  • 1 <= coins[i] <= 5000

Try it yourself

Solution

Title

Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions

Upgrade