题解 | #跳台阶-斐波那契数列#
跳台阶
https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
# @param number int整型
# @return int整型
class Solution:
def jumpFloor(self , number: int) -> int:
# write code here
# f(n)=f(n-1)+f(n-2), 初始化f(0)=f(1)=1,后续根据公式计算
a = 1
b = 1
res = 1
for i in range(2, number+1):
res = a + b
a = b
b = res
return res
莉莉丝游戏公司福利 699人发布