标签:数列 一个 code number 覆盖 == ber offer 斐波那契
题目描述class Solution:
"""
如果number == 1,那么只有1种
即
f(1) == 1
f(2) == 2
...
f(n) = f(n-1) + f(n-2)
因此跟斐波那契数列是一样的,可用递归也可用循环求解
"""
def rectCover(self, number):
if number <= 2:
return number
# return self.rectCover(number - 1) + self.rectCover(number - 2)
a, b = 1, 2
for i in range(3, number + 1):
c = a + b
a = b
b = c
return b
标签:数列 一个 code number 覆盖 == ber offer 斐波那契
原文地址:https://blog.51cto.com/jayce1111/2379874