Skip to content

Commit 756e1ce

Browse files
solves nth tribonnnaci number
1 parent 4ce92b1 commit 756e1ce

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,13 @@
297297
| 1099 | 🔒 [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | |
298298
| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | [![Java](assets/java.png)](src/DistributeCandiesToPeople.java) | |
299299
| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | [![Java](assets/java.png)](src/DefangingAnIPAddress.java) | |
300-
| 1118 | [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | | |
301-
| 1119 | [Remove Vowels From String](https://leetcode.com/problems/remove-vowels-from-a-string) | | |
300+
| 1118 | 🔒 [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | | |
301+
| 1119 | 🔒 [Remove Vowels From String](https://leetcode.com/problems/remove-vowels-from-a-string) | | |
302302
| 1122 | [Relative Sort Array](https://leetcode.com/problems/relative-sort-array) | | |
303303
| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | [![Java](assets/java.png)](src/NumberOfEquivalentDominoPairs.java) | |
304-
| 1133 | [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | |
305-
| 1134 | [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | |
306-
| 1137 | [Nth Tribonacci Number]() | | |
304+
| 1133 | 🔒 [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | |
305+
| 1134 | 🔒 [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | |
306+
| 1137 | [Nth Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number) | [![Java](assets/java.png)](src/NthTribonacciNumber.java) | |
307307
| 1150 | [Check if Number is Majority Element in Sorted Array](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | | |
308308
| 1154 | [Day of The Year](https://leetcode.com/problems/day-of-the-year) | | |
309309
| 1160 | [Find Words That Can Be Formed By Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | | |

src/NthTribonacciNumber.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class NthTribonacciNumber {
2+
public int tribonacci(int n) {
3+
if (n == 0) return 0;
4+
if (n <= 2) return 1;
5+
int a = 0, b = 1, c = 1, temp;
6+
while (n - 2 > 0) {
7+
temp = c;
8+
c = a + b + c;
9+
a = b;
10+
b = temp;
11+
n--;
12+
}
13+
return c;
14+
}
15+
}

0 commit comments

Comments
 (0)