We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5161ef7 + 52452bc commit 91f3a78Copy full SHA for 91f3a78
java/518-Coin-Change-2.java
@@ -0,0 +1,24 @@
1
+// Dynammic Programming - Tabulation
2
+// Time Complexity (n * amount) | Space Complexity (amount) where n is the length of coins
3
+class Solution {
4
+ public int change(int amount, int[] coins) {
5
+
6
+ int n = coins.length;
7
+ int[] dp = new int[amount + 1];
8
+ Arrays.fill(dp, 0);
9
10
+ // if amount is 0, there is only 1 way of making change (no money)
11
+ dp[0] = 1;
12
13
+ for (int coin: coins){
14
+ for (int i = 1; i <= amount; i++){
15
+ if (coin <= i){
16
+ dp[i] = dp[i] + dp[i - coin];
17
+ }
18
19
20
21
+ return dp[amount];
22
23
24
+}
0 commit comments