给定不同面额的硬币和一个总金额。写出函数来计算可以凑成总金额的硬币组合数。假设每一种面额的硬币有无限个。 amount表示需要凑成的金额
public class LC518 {
public int change(int amount, int[] coins) {
if (coins == null) {
return 0;
}
int[] dp = new int[amount + 1];
dp[0] = 1;
for (int c : coins) {
for (int i = c; i <= amount; i++) {
dp[i] = dp[i] + dp[i - c];
}
}
return dp[amount];
}
}