美文网首页面试算法
牛客-剑指0ffer-斐波那契数列

牛客-剑指0ffer-斐波那契数列

作者: wenyilab | 来源:发表于2019-07-27 08:22 被阅读1次

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

    # -*- coding:utf-8 -*-
    class Solution:
        def Fibonacci(self, n):
            # write code here
            temp = [0,1]
            while len(temp) <= n:
                temp.append(temp[-1] + temp[-2])
                
            return temp[n]
    

    相关文章

      网友评论

        本文标题:牛客-剑指0ffer-斐波那契数列

        本文链接:https://www.haomeiwen.com/subject/wplsrctx.html