Update 0070.爬楼梯.md

This commit is contained in:
fw_qaq
2023-04-10 15:36:23 +08:00
committed by GitHub
parent abbcbe1ed0
commit 03f037afeb

View File

@ -454,19 +454,16 @@ public class Solution {
```rust ```rust
impl Solution { impl Solution {
pub fn climb_stairs(n: i32) -> i32 { pub fn climb_stairs(n: i32) -> i32 {
if n <= 2 { if n <= 1 {
return n; return n;
} }
let mut a = 1; let (mut a, mut b, mut f) = (1, 1, 0);
let mut b = 2; for _ in 2..=n {
let mut f = 0;
for i in 2..n {
f = a + b; f = a + b;
a = b; a = b;
b = f; b = f;
} }
return f; f
}
} }
``` ```