1 class Solution: 2 def tribonacci(self, n: int) -> int: 3 if n == 0: 4 return 0 5 elif n == 1: 6 return 1 7 elif n == 2: 8 return 1 9 else: 10 dp = [0] * (n + 1) 11 dp[1] = 1 12 dp[2] = 1 13 for i in range(3,n+1): 14 dp[i] = dp[i-1] + dp[i-2] + dp[i-3] 15 return dp[n]