#518
Coin Change II
medium· 2-D DPruns: 0You are given an integer array coins representing different denominations of coins and an integer amount representing a total amount of money. Return the number of combinations that make up that amount. If that amount cannot be made up by any combination of coins, return 0. You may assume that you have an infinite number of each kind of coin.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 263
class Solution:
def change(self, amount: int, coins: list[int]) -> int:
dp = [0] * (amount + 1)
dp[0] = 1
for coin in coins:
for a in range(coin, amount + 1):
dp[a] += dp[a - coin]
return dp[amount]
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.