剑指Offer--6. 斐波那契数列

2019-04-06  本文已影响0人  lazydecoder
class Solution:
    def Fibonacci(self, n):
        # write code here
        if n == 0:
            return 0
        elif n == 1 or n == 2:
            return 1
        else :
            a = 1
            b = 1
            for i in range(3,n):
                c = a+b
                a = b
                b = c
            return a+b
上一篇下一篇

猜你喜欢

热点阅读