Skip to content

Commit b748374

Browse files
committedFeb 7, 2025
Add solution #1137
1 parent f52fdb0 commit b748374

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@
381381
1103|[Distribute Candies to People](./1103-distribute-candies-to-people.js)|Easy|
382382
1108|[Defanging an IP Address](./1108-defanging-an-ip-address.js)|Easy|
383383
1122|[Relative Sort Array](./1122-relative-sort-array.js)|Easy|
384+
1137|[N-th Tribonacci Number](./1137-n-th-tribonacci-number.js)|Easy|
384385
1161|[Maximum Level Sum of a Binary Tree](./1161-maximum-level-sum-of-a-binary-tree.js)|Medium|
385386
1189|[Maximum Number of Balloons](./1189-maximum-number-of-balloons.js)|Easy|
386387
1200|[Minimum Absolute Difference](./1200-minimum-absolute-difference.js)|Easy|
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 1137. N-th Tribonacci Number
3+
* https://leetcode.com/problems/n-th-tribonacci-number/
4+
* Difficulty: Easy
5+
*
6+
* The Tribonacci sequence Tn is defined as follows:
7+
*
8+
* T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
9+
*
10+
* Given n, return the value of Tn.
11+
*/
12+
13+
/**
14+
* @param {number} n
15+
* @return {number}
16+
*/
17+
var tribonacci = function(n) {
18+
const nums = [0, 1, 1];
19+
20+
for (let i = 3; i <= n; i++) {
21+
nums.push(nums[i - 3] + nums[i - 2] + nums[i - 1]);
22+
}
23+
24+
return nums[n];
25+
};

0 commit comments

Comments
 (0)
Please sign in to comment.