n<=39
递归实现:
class Solution(): def Fibnacci(self,n): if n <= 0: return 0 if n == 1: return 1 return self.Fibnacci(n-1) + self.Fibnacci(n-2)
非递归实现:
def Fibnacci(n): result = [0,1] if n <= 1: return result[n] for i in range(2,n+1): result.append(result[i-1]+result[i-2]) return result[n]
原文:https://www.cnblogs.com/tianqizhi/p/9610372.html