题解 | #斐波那契数列#

斐波那契数列

http://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3

# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param n int整型 
# @return int整型
# 给一个python的,就只会做入门题目......
#一开始用递归超时了,就用了查表
class Solution:
    def Fibonacci(self , n: int) -> int:
        # write code here
        res=[0,1,1]
        if n==1 or n==2:
            return res[n]
        index=3
        while index<=n:
            temp=res[index-1]+res[index-2]
            res.append(temp)
            index+=1
        return res[-1]
全部评论

相关推荐

漂亮的海豚在炒股:把西电加粗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务