The Fibonacci sequence of "Sword Finger Offer"

The Fibonacci sequence of "Sword Finger Offer"

I don't know where I am going, but I am already on my way!
Time is hurried, although I have never met, but I met Yusi, it is really a great fate, thank you for your visit!
  • Topic :
    Everyone knows the Fibonacci sequence. Now it is required to input an integer n. Please output the nth term of the Fibonacci sequence (starting from 0, the 0th term is 0, and the 1st term is 1).n≤39
  • Example :
示例 1 :
输入:4
返回值:3
  • Code 1:
# -*- coding:utf-8 -*-
class Solution:
    def Fibonacci(self, n):
        a,b = 0,1
        for i in range(n):
            a,b = b,a+b
        return a
  • Algorithm description:
    Set the initial value, and then iterate one by one, pay attention to what is returned a, not b.

Guess you like

Origin blog.csdn.net/qq_34331113/article/details/114915043