5
5
*
6
6
* <p>Tested against: https://leetcode.com/problems/coin-change
7
7
*
8
- * Run locally:
9
- *
10
- * ./gradlew run -Palgorithm=dp.CoinChange
11
- *
8
+ * <p> Run locally:
9
+ *
10
+ * <p> ./gradlew run -Palgorithm=dp.CoinChange
11
+ *
12
12
* @author William Fiset, [email protected]
13
13
*/
14
14
package com .williamfiset .algorithms .dp ;
@@ -66,7 +66,7 @@ public static Solution coinChange(int[] coins, final int n) {
66
66
}
67
67
}
68
68
69
- // p(dp);
69
+ p (dp );
70
70
71
71
Solution solution = new Solution ();
72
72
@@ -78,7 +78,7 @@ public static Solution coinChange(int[] coins, final int n) {
78
78
}
79
79
80
80
for (int change = n , coinIndex = m ; coinIndex > 0 ; ) {
81
- int coinValue = coins [coinIndex - 1 ];
81
+ int coinValue = coins [coinIndex - 1 ];
82
82
boolean canSelectCoin = change - coinValue >= 0 ;
83
83
if (canSelectCoin && dp [coinIndex ][change - coinValue ] < dp [coinIndex ][change ]) {
84
84
solution .selectedCoins .add (coinValue );
@@ -145,7 +145,17 @@ private static int coinChangeRecursive(int n, int[] coins, int[] dp) {
145
145
public static void main (String [] args ) {
146
146
// example1();
147
147
// example2();
148
- example3 ();
148
+ // example3();
149
+ example4 ();
150
+ }
151
+
152
+ private static void example4 () {
153
+ int n = 11 ;
154
+ int [] coins = {2 , 4 , 1 };
155
+ System .out .println (coinChange (coins , n ).minCoins );
156
+ System .out .println (coinChangeSpaceEfficient (coins , n ));
157
+ System .out .println (coinChangeRecursive (coins , n ));
158
+ System .out .println (coinChange (coins , n ).selectedCoins );
149
159
}
150
160
151
161
private static void example1 () {
0 commit comments