Merge pull request #2105 from fwqaaq/patch-27

Update 0070.爬楼梯完全背包版本.md about rust
This commit is contained in:
程序员Carl
2023-06-09 07:35:04 +08:00
committed by GitHub

View File

@ -225,8 +225,25 @@ function climbStairs(n: number): number {
};
```
Rust:
```rust
impl Solution {
pub fn climb_stairs(n: i32) -> i32 {
let (n, m) = (n as usize, 2);
let mut dp = vec![0; n + 1];
dp[0] = 1;
for i in 1..=n {
for j in 1..=m {
if i >= j {
dp[i] += dp[i - j];
}
}
}
dp[n]
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">