[LeetCode]Coin Change
经典动态规划
public class Solution { public int coinChange(int[] coins, int amount) { int[] record = new int[amount + 1]; record[0] = 1; for (int i = 1; i <= amount; i++) { record[i] = Integer.MAX_VALUE / 2; for (int j = 0; j < coins.length; j++) { int index = i - coins[j]; if (index >= 0 && record[index] != 0) { record[i] = Math.min(record[i], record[index] + 1); } } } return record[amount] == Integer.MAX_VALUE / 2 ? -1 : record[amount] - 1; } }