1137. 第 N 个泰波那契数
为保证权益,题目请参考 1137. 第 N 个泰波那契数(From LeetCode).
解决方案1
Python
python
# 1137. 第 N 个泰波那契数
# https://leetcode-cn.com/problems/n-th-tribonacci-number/
class Solution:
def tribonacci(self, n: int) -> int:
ans = [0, 1, 1]
if n <= 2:
return ans[n]
for i in range(3, n + 1):
ans.append(ans[i - 3] + ans[i - 2] + ans[i - 1])
return ans[-1]
if __name__ == "__main__":
pass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18