#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param n int整型
# @return int整型
#
class Solution:
def Fibonacci(self , n: int) -> int:
# write code here
if n == 1 or n == 2:
return 1
# 当前项前面的第二项。
num1 = 1
# 当前项前面的第一项。
num2 = 1
for _ in range(2, n):
current_num = num1 + num2
num1 = num2
num2 = current_num
return current_num

京公网安备 11010502036488号