1137. N-th Tribonacci Number(Memory Usage: 13.9 MB, less than 100.00% of Python3)

其实思路很简单,套用一下普通斐波那契数列的非递归做法即可,不过这个成绩我一定要纪念一下,哈哈哈哈哈

代码在这儿:

class Solution:
    def tribonacci(self, n: int) -> int:
        a, b, c =0, 1, 1
        if n is 0:
            return 0
        if n is 1:
            return 1
        if n is 2:
            return 1
        for i in range(2, n):
            a, b ,c = b, c, a+b+c
        return c

猜你喜欢

转载自www.cnblogs.com/chuaner/p/11667852.html
今日推荐