Skip to content

Commit 269f860

Browse files
committed
Apr 24
1 parent fd703e1 commit 269f860

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def tribonacci(self, n: int) -> int:
3+
if n <= 2:
4+
return 1 if n else 0
5+
6+
p1, p2, p3 = 0, 1, 1
7+
for _ in range(n-2):
8+
p1, p2, p3 = p2, p3, p1+p2+p3
9+
return p3
10+
11+
12+
def main():
13+
n = 4
14+
assert Solution().tribonacci(n) == 4
15+
16+
n = 25
17+
assert Solution().tribonacci(n) == 1389537
18+
19+
20+
if __name__ == '__main__':
21+
main()

2024-04-April-LeetCoding-Challenge/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
| April 21 | []() | | |
2727
| April 22 | [752. Open the Lock](https://leetcode.com/problems/open-the-lock/) | Medium | Unsolved |
2828
| April 23 | [310. Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees/) | Medium | Unsolved |
29-
| April 24 | []() | | |
29+
| April 24 | [1137. N-th Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number/) | Easy | Solved |
3030
| April 25 | []() | | |
3131
| April 26 | []() | | |
3232
| April 27 | []() | | |
@@ -38,6 +38,6 @@
3838
## Summary
3939
| Level | Problems | Solved | Unsolved |
4040
| --- | --- | --- | --- |
41-
| Easy | 8 | 8 | 0 |
41+
| Easy | 9 | 9 | 0 |
4242
| Medium | 11 | 6 | 5 |
4343
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)