题解 | #斐波那契数列#
斐波那契数列
https://www.nowcoder.com/practice/ee5d403c1172487f8c7915b3c3d924c6
# x = int(input()) # def pbnq(x): # if x == 1 or x ==2: # return 1 # return pbnq(x-1) + pbnq(x-2) # print(pbnq(x)) #递归失败,结果运行超时,需要使用数组进行动态规划 k = int(input()) nums = [1,1] if k <= 2: print(1) else: for x in range(2,k): nums.append(nums[x-1]+nums[x-2]) print(nums[k-1])