Problem
- Leetcode 1137. N-th Tribonacci Number - DP
- Level: Easy
- Link
My Approach
Classic fibonacci problem with DP algorithm
class Solution:
def tribonacci(self, n: int) -> int:
arr = [0, 1, 1]
if n < 3:
return arr[n]
for i in range(3, n + 1):
nxt = arr[i - 1] + arr[i - 2] + arr[i - 3]
arr.append(nxt)
return arr[n]
'개발공부 > algorithm' 카테고리의 다른 글
[프로그래머스][python] 기능 개발 - list (0) | 2021.05.18 |
---|---|
[프로그래머스][python] 짝지어 제거하기 - stack/queue (0) | 2021.05.18 |
[Leetcode][python] 938: Range sum BST - BFS (0) | 2021.05.16 |
[Leetcode][python] 563. Binary Tree Tilt - DFS (0) | 2021.05.16 |
[Leetcode][python] 107: Binary Tree Level order Traversal II (0) | 2021.05.15 |