We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f966843 + 10a9497 commit f7c00e7Copy full SHA for f7c00e7
climbing-stairs/ymir0804.java
@@ -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