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 46cebfe commit f486e1fCopy full SHA for f486e1f
coin-change/casentino.ts
@@ -0,0 +1,12 @@
1
+function coinChange(coins: number[], amount: number): number {
2
+ const dp = new Array(amount + 1).fill(amount);
3
+ dp[0] = 0;
4
+ for (let i = 1; i <= amount; i++) {
5
+ for (let j = 0; j < coins.length; j++) {
6
+ if (i - coins[j] >= 0) {
7
+ dp[i] = Math.min(dp[i - coins[j]] + 1, dp[i]);
8
+ }
9
10
11
+ return dp[amount] === Number.POSITIVE_INFINITY ? -1 : dp[amount];
12
+}
0 commit comments