File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
main/java/com/smlnskgmail/jaman/leetcodejava/easy
test/java/com/smlnskgmail/jaman/leetcodejava/easy Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .smlnskgmail .jaman .leetcodejava .easy ;
2
+
3
+ // https://leetcode.com/problems/n-th-tribonacci-number
4
+ public class NthTribonacciNumber {
5
+
6
+ private final int input ;
7
+
8
+ public NthTribonacciNumber (int input ) {
9
+ this .input = input ;
10
+ }
11
+
12
+ public int solution () {
13
+ int [] nums = new int [38 ];
14
+ nums [0 ] = 0 ;
15
+ nums [1 ] = 1 ;
16
+ nums [2 ] = 1 ;
17
+ for (int i = 3 ; i <= input ; i ++) {
18
+ nums [i ] = nums [i - 3 ] + nums [i - 2 ] + nums [i - 1 ];
19
+ }
20
+ return nums [input ];
21
+ }
22
+
23
+ }
Original file line number Diff line number Diff line change
1
+ package com .smlnskgmail .jaman .leetcodejava .easy ;
2
+
3
+ import org .junit .Test ;
4
+
5
+ import static org .junit .Assert .assertEquals ;
6
+
7
+ public class NthTribonacciNumberTest {
8
+
9
+ @ Test
10
+ public void defaultTest () {
11
+ assertEquals (
12
+ 4 ,
13
+ new NthTribonacciNumber (4 ).solution ()
14
+ );
15
+ }
16
+
17
+ }
You can’t perform that action at this time.
0 commit comments