Leetcode 1236 Solution

This article provides solution to leetcode question 1236 (n-th-tribonacci-number)

https://leetcode.com/problems/n-th-tribonacci-number

Solution

class Solution:
    def tribonacci(self, n: int) -> int:
        if n == 0:
            return 0
        elif n == 1 or n == 2:
            return 1

        a = 0
        b = 1
        c = 1

        i = 2

        while i < n:
            d = a + b + c
            a = b
            b = c
            c = d

            i += 1

        return c