题目链接:https://leetcode-cn.com/problems/coin-change-2/
难度:中等

描述:
给你一个整数数组 coins 表示不同面额的硬币,另给一个整数 amount 表示总金额。
请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额,返回 0
假设每一种面额的硬币有无限个。
题目数据保证结果符合 32 位带符号整数。

题解

  1. class Solution:
  2. def change(self, amount: int, coins: List[int]) -> int:
  3. r = [0] * (amount + 1)
  4. r[0] = 1
  5. for coin in coins:
  6. for i in range(coin, amount+1):
  7. r[i] += r[i-coin]
  8. return r[amount]