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 fdf3120 commit 6f38b25Copy full SHA for 6f38b25
coin-change/soobing3.ts
@@ -0,0 +1,13 @@
1
+function coinChange(coins: number[], amount: number): number {
2
+ const dp = new Array(amount + 1).fill(Infinity);
3
+ dp[0] = 0;
4
+
5
+ for (let i = 0; i <= amount; i++) {
6
+ for(const coin of coins) {
7
+ if (i - coin >= 0 && dp[i - coin] !== Infinity) {
8
+ dp[i] = Math.min(dp[i], dp[i - coin] + 1);
9
+ }
10
11
12
+ return dp[amount] === Infinity ? -1 : dp[amount];
13
+};
0 commit comments