이직하고만다(분노)

99클럽 코테 스터디 41일차 TIL + 리트코드 DP

xxo_ohii 2024. 8. 31. 19:13
728x90

 

- 주제 : 동적계획법

- 링크 리트코드 : https://leetcode.com/problems/n-th-tribonacci-number/

 

class Solution:
    def tribonacci(self, n: int) -> int:
        if n == 0:
            return 0
        elif n == 1 or n == 2:
            return 1

        t0, t1, t2 = 0, 1, 1
        for i in range(3, n + 1):
            t3 = t0 + t1 + t2
            t0, t1, t2 = t1, t2, t3

        return t2
Fn=Fn−1+Fn−2Fn=Fn−1+Fn−2F_n ...

 

트리보나치는 이런 느낌이다!

728x90