Skip to content

Commit 4381785

Browse files
committed
climbing-stairs
1 parent d682e93 commit 4381785

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

climbing-stairs/rlawjd10.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// 피보나치 수열
2+
class Solution {
3+
public:
4+
int climbStairs(int n) {
5+
6+
int prev1 = 1;
7+
int prev2 = 1;
8+
9+
if (n == 1) return prev1;
10+
11+
for (int i = 2; i <= n; i++) {
12+
int current = prev1 + prev2;
13+
prev2 = prev1;
14+
prev1 = current;
15+
}
16+
17+
return prev1;
18+
}
19+
};
20+
21+

0 commit comments

Comments
 (0)