memo = {} def fib(x): memKey = "%d"%x if hasattr(memo, memKey): return memo[memKey] if x >= 2: memo[memKey] = fib(x-1) + fib(x-2) return memo[memKey] return max(x, 0)
- memo = {}
- def fib(x):
- memKey = "%d"%x
- if hasattr(memo, memKey):
- return memo[memKey]
- if x >= 2:
return fib(x-1) + fib(x-2)return max(x, 0)- memo[memKey] = fib(x-1) + fib(x-2)
- return memo[memKey]
- return max(x, 0)