Untitled
unknown
javascript
2 years ago
481 B
24
Indexable
// change coins using array, tabulation (for optimization) coins = [3,5,10,15]; amount = 30; let dic = {}; function change(amount, start, end) { let temp = JSON.stringify([amount, start, end]); if (temp in dic) { return dic[temp]; } if (start === end || amount < 0) { return 0; } if (amount === 0) { return 1; } let a = change(amount - coins[start], start, end); let b = change(amount, start + 1, end); dic[temp] = a + b; return dic[temp]; }
Editor is loading...