-- coding:utf-8 --

write code here

# -*- coding:utf-8 -*-
class Solution:
    def Fibonacci(self, n):
        # write code here
        if n <= 1:
            return n
        else:
            Fzero = 0
            Fone = 1
            for i in range(2,n+1):
                Fn = Fone + Fzero
                Fzero = Fone
                Fone = Fn
            return Fn

这种不占内存,每次覆盖前面的值

-- coding:utf-8 --

write code here


# -*- coding:utf-8-*-
classSolution:
    def Fibonacci(self, n):
        # write code here
        ifn <= 1:
            returnn
        else:
            returnself.Fibonacci(n-1) + self.Fibonacci(n-2)


传统递归因为要从上往下无限递归,所以占内存太大了,我run的时候就给我报错了