Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int coinChange(int[] coins, int amount) {
- int[] dp = new int[amount+1];
- Arrays.fill(dp, -1);
- // 0 ways of making $0
- dp[0] = 0;
- for (int i = 1; i < amount+1; i++) {
- for (int c = 0; c < coins.length; c++) {
- if (i-coins[c] >= 0 && dp[i-coins[c]] != -1) {
- dp[i] = (dp[i] == -1) ? dp[i-coins[c]]+1 : Math.min(dp[i], dp[i-coins[c]]+1);
- }
- }
- }
- return dp[amount];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement