Skip to content

Commit 23eb005

Browse files
authored
Merge pull request #2415 from DaleStudy/week2
[DaleSeo] WEEK 2 Solutions
2 parents 95911bc + 9403c21 commit 23eb005

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

climbing-stairs/DaleSeo.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// TC: O(n)
2+
// SC: O(1)
3+
impl Solution {
4+
pub fn climb_stairs(n: i32) -> i32 {
5+
if n < 3 {
6+
return n;
7+
}
8+
let (mut pre, mut cur) = (1, 2);
9+
for _ in 3..=n {
10+
let next = pre + cur;
11+
pre = cur;
12+
cur = next;
13+
}
14+
cur
15+
}
16+
}

0 commit comments

Comments
 (0)