Skip to main content

1137. N-th Tribonacci Number

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

Python

class Solution:
def tribonacci(self, n: int) -> int:
if n < 3:
return [0, 1, 1][n]

t1, t2, t3 = 0, 1, 1
for i in range(3, n+1):
trib = t1+t2+t3
t1, t2, t3 = t2, t3, trib

return t3