mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Merge pull request #2105 from fwqaaq/patch-27
Update 0070.爬楼梯完全背包版本.md about rust
This commit is contained in:
@ -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">
|
||||
|
Reference in New Issue
Block a user