Skip to content

Commit 0beca12

Browse files
committed
climbing-stairs solution
1 parent 335b962 commit 0beca12

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

climbing-stairs/prgmr99.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
var climbStairs = function (n) {
6+
const memo = {};
7+
8+
function fibo(num, memo) {
9+
if (num === 1) return 1;
10+
if (num === 2) return 2;
11+
12+
if (memo[num]) {
13+
return memo[num];
14+
}
15+
16+
const result = fibo(num - 1, memo) + fibo(num - 2, memo);
17+
memo[num] = result;
18+
19+
return result;
20+
}
21+
22+
return fibo(n, memo);
23+
};

0 commit comments

Comments
 (0)