- 斐波那契数列,本质上和生兔子的原理一样,都是f(n) = f(n-1) + f(n-2)
class Solution: def jumpFloor(self, number): # write code here if number == 1 :return 1 if number == 2 :return 2 if not number:return None j = 2 nums1 = 1 nums2 = 2 while j < number: res = nums1 + nums2 nums1 = nums2 nums2 = res j += 1 return res