你們都知道斐波那契數列,如今要求輸入一個整數n,請你輸出斐波那契數列的第n項(從0開始,第0項爲0)。 n<=39code
# -*- coding:utf-8 -*- class Solution: def Fibonacci(self, n): # write code here x, y = 0 , 1 if n <= 0: return 0 elif n < 2: return 1 for _ in range(n - 1): x, y = y, x + y return y