@@ -0,0 +1,1045 @@
+package com.freetymekiyan.algorithms.level.medium;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * You are given coins of different denominations and a total amount of money amount. Write a function to compute the%0A * fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any%0A * combination of the coins, return -1.%0A * %3Cp%3E%0A * Example 1:%0A * coins = %5B1, 2, 5%5D, amount = 11%0A * return 3 (11 = 5 + 5 + 1)%0A * %3Cp%3E%0A * Example 2:%0A * coins = %5B2%5D, amount = 3%0A * return -1.%0A * %3Cp%3E%0A * Note:%0A * You may assume that you have an infinite number of each kind of coin.%0A * %3Cp%3E%0A * Tags: Dynamic Programming%0A */%0Apublic class CoinChange %7B%0A%0A    public int coinChange(int%5B%5D coins, int amount) %7B%0A        int%5B%5D res = new int%5Bamount + 1%5D;%0A        Arrays.fill(res, 1, amount + 1, amount + 1);%0A        for (int coin : coins) %7B%0A            for (int i = coin; i %3C res.length; i++) %7B%0A                res%5Bi%5D = Math.min(res%5Bi%5D, res%5Bi - coin%5D + 1);%0A            %7D%0A        %7D%0A        return res%5Bamount%5D == amount + 1 ? -1 : res%5Bamount%5D;%0A    %7D%0A%0A%7D%0A

add Coin Change