LeetCode: Climbing Stairs Solution

Memoized recursion

Implementation

1var climbStairs = function (n, memo = {}) {
2 if (n < 0) return 0
3 if (n <= 1) return 1
4 if (memo[n] !== undefined) return memo[n]
5 return (memo[n] = climbStairs(n - 1, memo) + climbStairs(n - 2, memo))
6}

References

Original problem

Comments

Loading comments...

Tags

leetcode

recursion

dynamic programming

Next Post

LeetCode: Binary Tree Right Side View

Previous Post

LeetCode: Two Sum

Classical hash table problem

HoningJS

Search Posts