Skip to content

Commit 54bc2e1

Browse files
committed
climbing-stairs
1 parent dc7d76d commit 54bc2e1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

climbing-stairs/sooooo-an.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function climbStairs(n: number): number {
2+
type Cache = { [key: number]: number };
3+
4+
const cache: Cache = {
5+
2: 2,
6+
1: 1,
7+
};
8+
9+
const fibonacci = (n: number, cache: Cache) => {
10+
if (n in cache) {
11+
return cache[n];
12+
} else {
13+
cache[n] = fibonacci(n - 2, cache) + fibonacci(n - 1, cache);
14+
return cache[n];
15+
}
16+
};
17+
18+
return fibonacci(n, cache);
19+
}

0 commit comments

Comments
 (0)