Update 0070.爬楼梯.md
This commit is contained in:
parent
ba03a17e68
commit
abbcbe1ed0
|
|
@ -470,6 +470,23 @@ impl Solution {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
dp 数组
|
||||||
|
|
||||||
|
```rust
|
||||||
|
impl Solution {
|
||||||
|
pub fn climb_stairs(n: i32) -> i32 {
|
||||||
|
let n = n as usize;
|
||||||
|
let mut dp = vec![0; n + 1];
|
||||||
|
dp[0] = 1;
|
||||||
|
dp[1] = 1;
|
||||||
|
for i in 2..=n {
|
||||||
|
dp[i] = dp[i - 1] + dp[i - 2];
|
||||||
|
}
|
||||||
|
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">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue