Skip to content

Commit 3a10516

Browse files
committed
Climbing Stairs
1 parent fd093e9 commit 3a10516

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

climbing-stairs/sunjae95.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @description
3+
* brainstorming:
4+
* Dynamic Programming
5+
*
6+
* time complexity: O(n)
7+
* space complexity: O(n)
8+
*/
9+
10+
var climbStairs = function (n) {
11+
const dp = Array.from({ length: n + 1 }, () => 0);
12+
dp[1] = 1;
13+
dp[2] = 2;
14+
15+
for (let i = 3; i < n + 1; i++) dp[i] = dp[i - 1] + dp[i - 2];
16+
17+
return dp[n];
18+
};

0 commit comments

Comments
 (0)