Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7b9f698

Browse files
committedAug 30, 2024·
Climbing Stairs
1 parent d54cb10 commit 7b9f698

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 

‎climbing-stairs/hyejjun.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
var climbStairs = function (n) {
6+
if (n <= 2) return n;
7+
8+
let first = 1;
9+
let second = 2;
10+
11+
for (let i = 3; i <= n; i++) {
12+
let third = first + second;
13+
first = second;
14+
second = third;
15+
}
16+
17+
return second;
18+
};
19+
20+
console.log(climbStairs(2));
21+
console.log(climbStairs(3));
22+
console.log(climbStairs(4));
23+
console.log(climbStairs(5));
24+
25+
/*
26+
시간 복잡도: O(n)
27+
공간 복잡도: O(1)
28+
*/

0 commit comments

Comments
 (0)
Please sign in to comment.