https://leetcode.com/problems/n-th-tribonacci-number/
N-th Tribonacci Number - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
피보나치 문제와 99.9% 똑같지만 점화식이 이전의 세 수를 더한다는 차이점이 있습니다.
그러니 이름이 트리보나치겠죠? 간단하게 풀이했습니다.
class Solution:
def tribonacci(self, n: int) -> int:
dp = [0] * (38)
dp[0] = 0
dp[1] = 1
dp[2] = 1
for i in range(3,n+1):
dp[i] = dp[i-1] + dp[i-2] + dp[i-3]
return dp[n]
for i in range(0,26):
print(Solution().tribonacci(i))
728x90
'🔍 알고리즘 > Leetcode' 카테고리의 다른 글
[Python] Leetcode 746. Min Cost Climbing Stairs (Easy) (0) | 2022.07.22 |
---|---|
[Python] Leetcode 70. Climbing Stairs (Easy) (0) | 2022.07.22 |
[Python] Leetcode 509. Fibonacci Number (Easy) (0) | 2022.07.22 |
[Python] Leetcode 392. Is Subsequence (Easy) (0) | 2022.07.22 |
[Python] Leetcode 205. Isomorphic Strings (Easy) (0) | 2022.07.22 |