题解 | #斐波那契数列#

斐波那契数列

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]
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 12:10
点赞 评论 收藏
分享
今天 19:25
门头沟学院 Java
点赞 评论 收藏
分享
uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务