MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / climbStairs

Function climbStairs

javascript/0070-climbing-stairs.js:8–20  ·  view source on GitHub ↗
(n, index = 0)

Source from the content-addressed store, hash-verified

6 * @return {number}
7 */
8var climbStairs = (n, index = 0) => {
9 const isBaseCase1 = n < index;
10 if (isBaseCase1) return 0;
11
12 const isBaseCase2 = index === n;
13 if (isBaseCase2) return 1;
14
15 const [next, nextNext] = [index + 1, index + 2];
16 const left = climbStairs(n, next); /* Time O(2^N) | Space O(N) */
17 const right = climbStairs(n, nextNext); /* Time O(2^N) | Space O(N) */
18
19 return left + right;
20};
21
22/**
23 * DP - Top Down

Callers

nothing calls this directly

Calls 3

powerFunction · 0.85
initTabuFunction · 0.70
searchFunction · 0.70

Tested by

no test coverage detected