https://leetcode.com/problems/n-th-tribonacci-number/
class Solution:
def tribonacci(self, n: int) -> int:
dp = [j for j in range(n+1)]
ans = 0
for i in range(2, n+1):
dp[i] = dp[i-1] + dp[i-2]
T = dp
for j in range(3, n+1):
T[j] = T[j-3]+T[j-2]+T[j-1]
return T[n]
피보나치를 구해서 메모해놓고, 그걸 이용해서 N-th Tribonacci를 구하는 문제.
'알고리즘 > LeetCode' 카테고리의 다른 글
[LeetCode/C++]FirstBadVersion _ binary search (0) | 2021.10.05 |
---|---|
[LeetCode/python]4. Median of Two Sorted Arrays (0) | 2021.10.03 |
[LeetCode/python]Climbing Stairs/ dp (0) | 2021.10.02 |