feat: 0070.爬楼梯.md 增加 rust代码

This commit is contained in:
codeSu
2022-11-16 21:59:33 +08:00
parent 2d7b0e55ae
commit 9969795e06

View File

@ -303,7 +303,7 @@ var climbStairs = function(n) {
}; };
``` ```
TypeScript ### TypeScript
> 爬2阶 > 爬2阶
@ -447,7 +447,26 @@ public class Solution {
} }
``` ```
### Rust
```rust
impl Solution {
pub fn climb_stairs(n: i32) -> i32 {
if n <= 2 {
return n;
}
let mut a = 1;
let mut b = 2;
let mut f = 0;
for i in 2..n {
f = a + b;
a = b;
b = f;
}
return f;
}
}
```
<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">