We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9486032 commit 8b18aeaCopy full SHA for 8b18aea
Dynamic Programming/2D/Subsequences/CoinChangeII.java
@@ -0,0 +1,30 @@
1
+class CoinChangeII {
2
+ public int change(int amount, int[] coins) {
3
+ int n = coins.length;
4
+
5
+ int[][] dp = new int[n][amount+1];
6
7
+ for(int i = 0; i<n; i++){
8
+ dp[i][0] = 1;
9
+ }
10
11
+ for(int j = 1; j<amount+1; j++){
12
+ if(j != 0 && j%coins[0] == 0){
13
+ dp[0][j] = 1;
14
15
16
17
+ for(int i = 1; i<n; i++){
18
19
+ if(j>=coins[i]){
20
+ dp[i][j] = dp[i-1][j] + dp[i][j-coins[i]];
21
22
+ else{
23
+ dp[i][j] = dp[i-1][j];
24
25
26
27
28
+ return dp[n-1][amount];
29
30
+}
0 commit comments