Skip to content

Commit 80b64af

Browse files
authored
Merge pull request #167 from mincong-h/java
Coin-Change-2 (Java)
2 parents 661ed3f + 48884c1 commit 80b64af

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int change(int amount, int[] coins) {
3+
int[] combinations = new int[amount + 1];
4+
combinations[0] = 1;
5+
for (int coin : coins) {
6+
for (int i = coin; i <= amount; i++) {
7+
int prev = i - coin;
8+
if (prev >= 0) {
9+
combinations[i] += combinations[prev];
10+
}
11+
}
12+
}
13+
return combinations[amount];
14+
}
15+
}

0 commit comments

Comments
 (0)