Skip to content

Commit dc0069a

Browse files
committed
0518 chnage
1 parent f7a6254 commit dc0069a

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
| 0509 | [fib](./code/0509_fib) || Array | |
7272
| 0513 | [findBottomLeftValue](./code/0513_findBottomLeftValue) | ⭐⭐ | DFS, BFS, Tree | |
7373
| 0514 | [findRotateSteps](./code/0514_findRotateSteps) | ⭐⭐⭐ | DFS, DP | |
74+
| 0518 | [change](./code/0518_change) | ⭐⭐ | DP | 1️⃣ |
7475
| 0547 | [findCircleNum](./code/0547_findCircleNum) | ⭐⭐ | DFS, UN | |
7576
| 0605 | [canPlaceFlowers](./code/0605_canPlaceFlowers) || Greedy | |
7677
| 0628 | [maximumProduct](./code/0628_maximumProduct) || Array | |

code/0076_minWindow/minWindow-sliderwindow.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ var minWindow = function (s, t) {
4040
return '';
4141
}
4242
return s.substring(start, start + minLen);
43-
};
44-
45-
console.log(minWindow("a", "a"));
43+
};

code/0518_change/change-dp.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number} amount
3+
* @param {number[]} coins
4+
* @return {number}
5+
*/
6+
var change = function(amount, coins) {
7+
if (amount === 0) return 1;
8+
const dp = [1].concat(new Array(amount).fill(0));
9+
10+
for (let c = 0; c < coins.length; c++) {
11+
for (let i = 1; i <= amount; i++) {
12+
if (i - coins[c] >= 0) {
13+
dp[i] = dp[i] + dp[i - coins[c]];
14+
}
15+
}
16+
}
17+
18+
return dp[dp.length - 1];
19+
};
20+
21+
// 时间复杂度 O(M*N) N为amount长度,M为coins个数
22+
// 空间复杂度 O(N) N为amount长度

0 commit comments

Comments
 (0)