Created
May 7, 2018 12:45
-
-
Save alexzobi/59ca8369502a3c328c463903e847af5f to your computer and use it in GitHub Desktop.
coins - bottom-up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function change(n, coins){ | |
let combos = new Array(n+1).fill(0); | |
combos[0]= 1; | |
for (let coin of coins){ | |
for (let i=1; i<=n; i++){ | |
if(i >= coin){ | |
combos[i] += combos[i-coin] | |
} | |
} | |
console.log('coin', coin) | |
console.log('combos', combos) | |
} | |
return combos[n]; | |
} | |
change(25, [1,5,10,25]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment