Home [Easy] N-th Tribonacci Number
Post
Cancel

[Easy] N-th Tribonacci Number

โ€˜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];
    }
}
This post is licensed under CC BY 4.0 by the author.

[Medium] All Possible Full Binary Trees

[Development] MSA

Comments powered by Disqus.