coin循环要在外面 从小到大 不会有重复
1 class Solution { 2 public int change(int amount, int[] coins) { 3 // if(coins.length == 0) return 1; 4 int[] dp = new int[amount + 1]; 5 dp[0] = 1; 6 Arrays.sort(coins); 7 for(int j = 0; j < coins.length; j++){ 8 for(int i = 1; i <= amount; i++){ 9 if(coins[j] <= i){ 10 dp[i] += dp[i - coins[j]]; 11 } 12 } 13 } 14 return dp[amount]; 15 16 } 17 }
原文地址:https://www.cnblogs.com/goPanama/p/9870117.html
时间: 2024-10-15 08:11:32