(n, index = 0)
| 6 | * @return {number} |
| 7 | */ |
| 8 | var 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 |