题解 | #斐波那契数列#

斐波那契数列

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

# -*- coding:utf-8 -*-
class Solution:
    def Fibonacci(self, n):
        f1,f2,sum = 1,1,0
        if n==0:
            return 0
        if n <= 2:
            return f1
        for i in range(n-2):
            sum = f1 + f2
            f1 = f2
            f2 = sum
        return sum
        # write code here
num = int(input())
s = Solution()
print(s.Fibonacci(num))
全部评论

相关推荐

李橙子:结果虽不够理想,但过程本身已是宝贵的淬炼。能把学习机会放在薪酬之前,证明你目光长远。先踏实进去,用这段时间扎实学好Python后端,把公司项目吃透,你的价值会在下一份工作中完全体现。这个起点,值得。
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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