python 斐波那契数列

题目描述

大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。

n<=39

# -*- coding:utf-8 -*-
class Solution:
    def Fibonacci(self, n):
        # write code here
        
        x=[0,1]
        for i in range(n-1):
            x.append(x[-1]+x[-2])
        return x[n]

猜你喜欢

转载自blog.csdn.net/qq_42707449/article/details/81101393