1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| class Solution { public int change(int amount, int[] coins) { int[][] dp = new int[coins.length + 1][amount + 1];
for (int i = 0; i <= coins.length ; i++) { dp[i][0] = 1; }
for (int i = 1; i <= coins.length; i++) { for (int j = 1; j <= amount ; j++) { if (j - coins[i-1] >= 0) { dp[i][j] = dp[i-1][j] + dp[i][j - coins[i - 1]]; }else { dp[i][j] = dp[i - 1][j]; } } } return dp[coins.length][amount]; } }
|