File tree Expand file tree Collapse file tree 1 file changed +0
-25
lines changed
Expand file tree Collapse file tree 1 file changed +0
-25
lines changed Original file line number Diff line number Diff line change @@ -15,28 +15,3 @@ export const change = (coins, amount) => {
1515 }
1616 return combinations [ amount ]
1717}
18- function minimumCoins ( coins , amount ) {
19- // minimumCoins[i] will store the minimum coins needed for amount i
20- const minimumCoins = new Array ( amount + 1 ) . fill ( 0 )
21-
22- minimumCoins [ 0 ] = 0
23-
24- for ( let i = 1 ; i < amount + 1 ; i ++ ) {
25- minimumCoins [ i ] = Number . MAX_SAFE_INTEGER
26- }
27- for ( let i = 1 ; i < amount + 1 ; i ++ ) {
28- for ( let j = 0 ; j < coins . length ; j ++ ) {
29- const coin = coins [ j ]
30- if ( coin <= i ) {
31- const subRes = minimumCoins [ i - coin ]
32- if (
33- subRes !== Number . MAX_SAFE_INTEGER &&
34- subRes + 1 < minimumCoins [ i ]
35- ) {
36- minimumCoins [ i ] = subRes + 1
37- }
38- }
39- }
40- }
41- return minimumCoins [ amount ]
42- }
You can’t perform that action at this time.
0 commit comments