Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions java/518-Coin-Change-2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Dynammic Programming - Tabulation
// Time Complexity (n * amount) | Space Complexity (amount) where n is the length of coins
class Solution {
public int change(int amount, int[] coins) {

int n = coins.length;
int[] dp = new int[amount + 1];
Arrays.fill(dp, 0);

// if amount is 0, there is only 1 way of making change (no money)
dp[0] = 1;

for (int coin: coins){
for (int i = 1; i <= amount; i++){
if (coin <= i){
dp[i] = dp[i] + dp[i - coin];
}
}
}

return dp[amount];

}
}