We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c35048 commit 8deee8dCopy full SHA for 8deee8d
coin-change/hi-rachel.ts
@@ -0,0 +1,11 @@
1
+function coinChange(coins: number[], amount: number): number {
2
+ const dp = [0, ...new Array(amount).fill(amount + 1)];
3
+ for (let i = 0; i <= amount; i++) {
4
+ for (const coin of coins) {
5
+ if (coin <= i) {
6
+ dp[i] = Math.min(dp[i], dp[i - coin] + 1);
7
+ }
8
9
10
+ return dp[amount] < amount + 1 ? dp[amount] : -1;
11
+}
0 commit comments