Open fockspaces opened 11 months ago
use tuple with three elements to maintain the relationship. keep updating unitil we find the ans
class Solution: def tribonacci(self, n: int) -> int: prev = (0, 1, 1) if n < 3: return prev[n] for i in range(2, n): prev = prev[1], prev[2], prev[0] + prev[1] + prev[2] return prev[2]
use tuple with three elements to maintain the relationship. keep updating unitil we find the ans