Skip to content

Commit 5e2178f

Browse files
committed
Climbing Stairs
1 parent cbbad7b commit 5e2178f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

climbing-stairs/casentino.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function climbStairs(n: number): number {
2+
const memo = new Array(n + 1).fill(-1);
3+
function climb(stair: number) {
4+
if (stair === 0) {
5+
return 1;
6+
}
7+
if (stair < 0) {
8+
return 0;
9+
}
10+
if (memo[stair] !== -1) {
11+
return memo[stair];
12+
}
13+
memo[stair] = climb(stair - 1) + climb(stair - 2);
14+
return memo[stair];
15+
}
16+
return climb(n);
17+
}

0 commit comments

Comments
 (0)