Skip to content

Commit f7c00e7

Browse files
authored
Merge pull request #2121 from ymir0804/main
[ymir0804] WEEK 03 solutions
2 parents f966843 + 10a9497 commit f7c00e7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

climbing-stairs/ymir0804.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public int climbStairs(int n) {
3+
int result = 0;
4+
int first = 1;
5+
int second = 2;
6+
int third = 3;
7+
if (n == 1) {
8+
return first;
9+
} else if (n == 2) {
10+
return second;
11+
} else if (n == 3) {
12+
return third;
13+
}
14+
15+
for (int i = 4; i <= n; i++) {
16+
result = second + third;
17+
second = third;
18+
third = result;
19+
}
20+
return result;
21+
}
22+
}

0 commit comments

Comments
 (0)