Leetcode 1137. N-th Tribonacci Number [Python]

class Solution:
    def tribonacci(self, n: int) -> int:
        res = []
        res.append(0)
        res.append(1)
        res.append(1)
        if n <= 2:
            return res[n]
        for i in range(3, n+1):
            temp = res[i-1] + res[i-2] + res[i-3]
            res.append(temp)
        return res[-1]

你可能感兴趣的:(Leetcode学习记录)