链接: 原文链接.
class Solution: def numWays(self, n: int) -> int: # f(0) = 1, f(1) = 1, f(2) = 2, # f(3) = 3 f(4) = 5, f(5) = 8 # 此题类似于上一道斐波那契数列,只不过是从第二个数字1开始的。 a, b = 1, 1 for i in range(n): a, b = b, a+b return a % 1000000007
链接: 原文链接.
class Solution: def numWays(self, n: int) -> int: # f(0) = 1, f(1) = 1, f(2) = 2, # f(3) = 3 f(4) = 5, f(5) = 8 # 此题类似于上一道斐波那契数列,只不过是从第二个数字1开始的。 a, b = 1, 1 for i in range(n): a, b = b, a+b return a % 1000000007