Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitec39f0a

Browse files
Merge pull requestyoungyangyang04#473 from jackeyjia/patch-6
add js solution for coinChange
2 parents6e23fc4 +32525d3 commitec39f0a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎problems/0322.零钱兑换.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,26 @@ func min(a, b int) int {
304304

305305
```
306306

307+
Javascript:
308+
```javascript
309+
constcoinChange= (coins,amount)=> {
310+
if(!amount) {
311+
return0;
312+
}
313+
314+
let dp=Array(amount+1).fill(Infinity);
315+
dp[0]=0;
316+
317+
for(let i=0; i<coins.length; i++) {
318+
for(let j= coins[i]; j<= amount; j++) {
319+
dp[j]=Math.min(dp[j- coins[i]]+1, dp[j]);
320+
}
321+
}
322+
323+
return dp[amount]===Infinity?-1: dp[amount];
324+
}
325+
```
326+
307327

308328

309329
-----------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp