Recursion: Fibonacci Numbers

  • + 0 comments

    Python Dynamic programming

    def fibonacci(n, memo=None):
        if memo is None:
            memo = [None] * (n + 1)
        if n <= 1:
            return n
        if memo[n] is None:
            memo[n] = fibonacci(n -2, memo) + fibonacci(n-1, memo)
        return memo[n]