Ad
Code
Diff
  • def fib(n):
        memo = {0:1, 1:1}
        def recursiveFib(n):
            if n not in memo:
                memo[n] = recursiveFib(n-1)+recursiveFib(n-2)
            return memo[n]
        return recursiveFib(n)
        
    • def fib(x):
    • f1, f2 = 0, 1
    • for x in range(x):
    • f1, f2 = f2, (f1 + f2)
    • return f2
    • def fib(n):
    • memo = {0:1, 1:1}
    • def recursiveFib(n):
    • if n not in memo:
    • memo[n] = recursiveFib(n-1)+recursiveFib(n-2)
    • return memo[n]
    • return recursiveFib(n)