leetcode 1137. N-th Fibonacci number Teppo

Teppo Fibonacci sequence Tn is defined as follows: 

T0 = ​​0, T1 = 1, T2 = 1, and the n> = 0 under the condition of Tn + 3 = Tn + Tn + 1 + Tn + 2

Give you integer n, please return the value of the n-th Fibonacci number Tn of Teppo.

 

Example 1:

Input: n = 4
Output: 4
explained:
T_3 +. 1. 1 + 0 = 2 =
T_4 for =. 1. 1 + 2 + 4 =

 1 class Solution {
 2     public int tribonacci(int n) {
 3         if(n==0)return 0;
 4         if(n==1||n==2)return 1;
 5         int nums[]=new int[n+1];
 6         nums[0]=0;
 7         nums[1]=1;
 8         nums[2]=1;
 9         for(int i=3;i<=n;i++){
10              nums[i]=nums[i-1]+nums[i-2]+nums[i-3];
11         }
12         return nums[n];
13     }
14 }

 

Guess you like

Origin www.cnblogs.com/gongzixiaobaibcy/p/11962021.html