โN-th Tribonacci Number (Easy)`
๐ Problem
https://leetcode.com/problems/n-th-tribonacci-number/>
๐ Answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public int tribonacci(int n) {
if (n == 0)
return 0;
if (n == 1 || n == 2)
return 1;
int[] Tribonacci = new int[n + 1];
Tribonacci[0] = 0;
Tribonacci[1] = 1;
Tribonacci[2] = 1;
for (int i = 3; i < n + 1; i++) {
Tribonacci[i] = Tribonacci[i-1] + Tribonacci[i-2] + Tribonacci[i-3];
}
return Tribonacci[n];
}
}
Comments powered by Disqus.