package leetcode;

/**
 * https://leetcode.com/problems/coin-change/
 */
public class Problem322 {
    public int coinChange(int[] coins, int amount) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {

    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -206,86 +206,899 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A
+Map%3CInteger, Integer%3E memo = new HashMap%3C%3E();%0A        int result = coinChange(coins, amount, memo);%0A        if (result == Integer.MAX_VALUE) %7B%0A            return -1;%0A        %7D%0A        return result - 1;%0A    %7D%0A%0A    private int coinChange(int%5B%5D coins, int amount, Map%3CInteger, Integer%3E memo) %7B%0A        if (amount %3C 0) %7B%0A            return Integer.MAX_VALUE;%0A        %7D else if (amount == 0) %7B%0A            return 1;%0A        %7D%0A        if (memo.containsKey(amount)) %7B%0A            return memo.get(amount);%0A        %7D%0A        int result = Integer.MAX_VALUE;%0A        for (int coin : coins) %7B%0A            int tmp = coinChange(coins, amount - coin, memo);%0A            if (tmp != Integer.MAX_VALUE) %7B%0A                result = Math.min(result, tmp);%0A            %7D%0A        %7D%0A        if (result != Integer.MAX_VALUE) %7B%0A            result++;%0A        %7D%0A        memo.put(amount, result);%0A        return result;
 %0A   

Solve problem 322