LeetCode #1137: N-th Tribonacci Number
β’ 48 words β’ 1 min β’ updated
LeetCode #1137: N-th Tribonacci Number:
python
class Solution:
def tribonacci(self, n: int) -> int:
from functools import cache
@cache
def tribo(n):
if n == 0:
return 0
if n in (1, 2):
return 1
return tribo(n - 1) + tribo(n - 2) + tribo(n - 3)
return tribo(n)