class Solution(object):
def zhuhanshu(self,n):
self.count = 0
self.memo = [-1 for i in range(n+1)]
def fib1(self,n):
if n == 0 or n == 1:
return 1
else:
return self.fib(n-1)+self.fib(n-2)
# 记忆化搜索
def fib2(self,n):
self.count += 1
if n == 1 or n == 0:
return 1
if self.memo[n] == -1:
self.memo[n] = self.fib2(n-1)+self.fib2(n-2)
return self.memo[n]
def fib2(self,n):
memo = [-1 for i in range(n+1)]
memo[0] = 1
memo[1] = 1
for i in range(2,n+1):
memo[i] = memo[i-1] + memo[i-2]
return memo[n]