大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0,第1项是1)。
n<=39
# -*- coding:utf-8 -*-
class Solution:
def Fibonacci(self, n):
# write code here
if n == 0:
return 0
elif n == 1:
return 1
f1 = 0
f2 = 1
index = n
res = 0
while index - 2 >= 0:
res = f1 + f2
f1 = f2
f2 = res
index -= 1
return res