其实思路很简单,套用一下普通斐波那契数列的非递归做法即可,不过这个成绩我一定要纪念一下,哈哈哈哈哈
代码在这儿:
class Solution:
def tribonacci(self, n: int) -> int:
a, b, c =0, 1, 1
if n is 0:
return 0
if n is 1:
return 1
if n is 2:
return 1
for i in range(2, n):
a, b ,c = b, c, a+b+c
return c