Skip to content

Commit d7eaecb

Browse files
committed
climbing stairs solution
1 parent 8cc2f40 commit d7eaecb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

climbing-stairs/Yu-Won.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 문제: https://leetcode.com/problems/climbing-stairs/description/
3+
*
4+
* 요구사항:
5+
* n개의 계단이 있을 때
6+
* 계단은 1, 2 칸씩 오를 수 있다.
7+
* 이 계단을 오르는 방법은 총 몇가지 인가?
8+
*
9+
* * */
10+
11+
const climbingStairs = (n) => {
12+
if(n <= 1) return 1;
13+
let prev1 = 1;
14+
let prev2 = 1;
15+
for(let i = 1; i < n; i++) {
16+
let current = prev1 + prev2;
17+
prev2 = prev1;
18+
prev1 = current;
19+
}
20+
21+
return prev1;
22+
}

0 commit comments

Comments
 (0)