package leecode;
/**
* 1137. 第 N 个泰波那契数
* 泰波那契序列 Tn 定义如下:
*
* T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0 的条件下 Tn+3 = Tn + Tn+1 + Tn+2
*
* 给你整数 n,请返回第 n 个泰波那契数 Tn 的值。
*
*
* @author Tang
* @date 2021/9/13
*/
public class Tribonacci {
public int tribonacci(int n) {
if(n == 0){
return 0;
}
int result = 0;
int n0 = 0;
int n1 = 1;
int n2 = 1;
for(int i = 1; i <= n; i++) {
if(i == 1 || i == 2) {
result = 1;
continue;
}
result = n0 + n1 + n2;
n0 = n1;
n1 = n2;
n2 = result;
}
return result;
}
public static void main(String[] args) {
}
}