class Solution {
public:
int tribonacci(int n) {
int result = 0;
if ( n <= 1 )
{
return n;
}
if ( n == 2 )
{
return 1;
}
int val_n_3 = 0;
int val_n_2 = 1;
int val_n_1 = 1;
int temp = 0;
for ( int i = 3; i <= n; i++ )
{
temp = val_n_3 + val_n_2 + val_n_1;
val_n_3 = val_n_2;
val_n_2 = val_n_1;
val_n_1 = temp;
}
result = temp;
return temp;
}
};