mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
Merge pull request #1598 from Jerry-306/patch-65
0070.爬楼梯JavaScript代码更新
This commit is contained in:
@ -187,12 +187,14 @@ func climbStairs(n int) int {
|
||||
JavaScript:
|
||||
```javascript
|
||||
var climbStairs = function(n) {
|
||||
const dp = new Array(n+1).fill(0);
|
||||
const weight = [1,2];
|
||||
const dp = new Array(n + 1).fill(0);
|
||||
const m = 2;
|
||||
dp[0] = 1;
|
||||
for(let i = 0; i <= n; i++){ //先遍历背包
|
||||
for(let j = 0; j < weight.length; j++){ // 再遍历物品
|
||||
if(i >= weight[j]) dp[i] += dp[i-weight[j]];
|
||||
for(let i = 1; i <= n; i++){
|
||||
for(let j = 1; j <= m; j++){
|
||||
if(i >= j) {
|
||||
dp[i] += dp[i - j];
|
||||
}
|
||||
}
|
||||
}
|
||||
return dp[n];
|
||||
|
Reference in New Issue
Block a user