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)∎
Connections
Shared tags