原题:
力扣链接:1137. 第 N 个泰波那契数
题目简述:
泰波那契序列 Tn 定义如下:
T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0 的条件下 Tn+3 = Tn + Tn+1 + Tn+2
给你整数 n,请返回第 n 个泰波那契数 Tn 的值。
解题思路
1.参考斐波拉契数的套路写出n>=3的函数
2.处理n = 0 1 2的特殊情况
3.over
C代码:
int tribonacci(int n){int first = 0;int second = 1;int third = 1;int fourth = 0;if(n >=3){while(n >= 3){fourth = first + second + third;first = second;second = third;third = fourth;n--;}}else {if(n == 1 || n == 2){fourth = 1;}}return fourth;}