20240804 Finished

This commit is contained in:
jackfiled 2024-08-04 10:55:34 +08:00
parent c935b56fbb
commit 0a058a3277
2 changed files with 44 additions and 1 deletions

View File

@ -193,4 +193,5 @@ mod p66_plus_one;
mod p172_factorial_trailing_zeroes; mod p172_factorial_trailing_zeroes;
mod p69_sqrtx; mod p69_sqrtx;
mod p50_powx_n; mod p50_powx_n;
mod p149_max_points_on_a_line; mod p149_max_points_on_a_line;
mod p70_climbing_stairs;

View File

@ -0,0 +1,42 @@
/**
* [70] Climbing Stairs
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn climb_stairs(n: i32) -> i32 {
if n == 1 {
return 1;
} else if n == 2 {
return 2;
}
let mut last_last = 1;
let mut last = 2;
for i in 3..=n {
let now = last + last_last;
last_last = last;
last = now;
}
last
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_70() {
assert_eq!(2, Solution::climb_stairs(2));
assert_eq!(3, Solution::climb_stairs(3));
assert_eq!(5, Solution::climb_stairs(4));
}
}