题目
来源:1137. 第 N 个泰波那契数 - 力扣(LeetCode) (leetcode-cn.com)
题目描述:
完整代码
public class SolutionTest {
public static void main(String[] args){
Solution slt = new Solution();
System.out.println(slt.tribonacci(5));
}
}
class Solution {
public int tribonacci(int n) {
if(n==0)
return 0;
if(n==1)
return 1;
if(n==2)
return 1;
int[] taibonaqie = new int[n+1];
taibonaqie[0] = 0;
taibonaqie[1] = 1;
taibonaqie[2] = 1;
for(int i = 3; i <= n; i++){
taibonaqie[i] = taibonaqie[i-1]+taibonaqie[i-2]+taibonaqie[i-3];
}
return taibonaqie[n];
}
}