欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

斐波那契

程序员文章站 2022-03-31 21:37:06
...
# -*- coding:utf-8 -*-
class Solution:
    def Fibonacci(self, n):
        # write code her
        if n <= 1:
            return n
        if n == 2:
            return 1
        a = 1
        b = 1
        sum = 0
        for i in range(n-2):
            sum = a + b
            a = b
            b = sum
        return sum