Skip to content

Commit

Permalink
Merge pull request youngyangyang04#2516 from kankan-web/master
Browse files Browse the repository at this point in the history
Update 0770.爬楼梯完全背包版
  • Loading branch information
youngyangyang04 authored May 8, 2024
2 parents ff257c3 + e2b9218 commit 65f5430
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions problems/0070.爬楼梯完全背包版本.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,33 @@ func main() {
```

### JavaScript:

```javaScript
var climbStairs = function (n) {
let dp = new Array(n + 1).fill(0);
dp[0] = 1;
// 排列题,注意循环顺序,背包在外物品在内
for (let j = 1; j <= n; j++) {//遍历背包
for (let i = 1; i <= 2; i++) {//遍历物品
if (j - i >= 0) dp[j] = dp[j] + dp[j - i];
}
}
return dp[n];
}
```

### TypeScript:

```typescript
var climbStairs = function (n: number): number {
let dp: number[] = new Array(n + 1).fill(0);
dp[0] = 1;
for (let j = 1; j <= n; j++) {//遍历背包
for (let i = 1; i <= 2; i++) {//遍历物品
if (j - i >= 0) dp[j] = dp[j] + dp[j - i];
}
}
return dp[n];
}
```

### Rust:

Expand Down

0 comments on commit 65f5430

Please sign in to comment.