Update 0070.爬楼梯完全背包版本.md about rust

This commit is contained in:
fwqaaq
2023-05-27 23:28:33 +08:00
committed by GitHub
parent 5cbb991588
commit 824ce31f87

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"> <p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">