Skip to content

Commit 0363257

Browse files
committed
Climbing Stairs solution
1 parent 6dff871 commit 0363257

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

climbing-stairs/kimyoung.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// found a pattern where the result is the addition of two previous elements,
2+
// but not sure if this is the expected answer
3+
var climbStairs = function (n) {
4+
let arr = new Array(n).fill(1);
5+
for (let i = 2; i <= n; i++) {
6+
arr[i] = arr[i - 2] + arr[i - 1];
7+
}
8+
return n === 1 ? 1 : arr[n];
9+
};
10+
11+
// time - O(n) iterate up to n times

0 commit comments

Comments
 (0)