LeetCode: Fibonacci Number Solution

Implementation

1var fib = function (n, mem = {}) {
2 if (mem[n] != null) return mem[n]
3 if (n < 2) return n
4 return (mem[n] = fib(n - 1, mem) + fib(n - 2, mem))
5}

References

Original problem

Comments

Loading comments...

Tags

leetcode

array

recursion

Next Post

LeetCode: Remove All Adjacent Duplicates In String II

HoningJS

Search Posts