Compute the $n$-th tribonacci number.
Intuition
Same as compute the $n$-th fibonacci number, we use three numbers to remember the state.
Approach
We use three numbers to represent $n-2$, $n-1$ and $n$-th tribonacci number respectively
Complexity
Time complexity: $$O(n)$$
Space complexity: $$O(1)$$
Code
|
|