青蛙跳台阶问题(斐波那契数列) python

class Solution:
def jump(self,n):
if n ==0:
return 0
elif n==1:
return 1
elif n ==1:
return 2
numN = 0
first = 1
second = 2
for i in range(3,n+1):
numN = first+second
first = second
second = numN
return numN

if __name__ =='__main__':
solution = Solution()
time = solution.jump(5)
print(time)

猜你喜欢

转载自www.cnblogs.com/turningli/p/12445913.html