File tree Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 1
- package DynamicProgramming ;
1
+ package test ;
2
2
import java .lang .*;
3
3
import java .io .*;
4
4
import java .util .*;
5
5
6
6
/**
7
- * @author Matteo Messmer https://github.com/matteomessmer
8
7
* Algorithm explanation https://www.educative.io/edpresso/longest-palindromic-subsequence-algorithm
9
8
*/
10
9
public class LongestPalindromicSubsequence {
@@ -19,9 +18,8 @@ public static void main(String[] args) {
19
18
System .out .println (b + " => " + bLPS );
20
19
}
21
20
22
- private static String LPS (String original ) {
23
- StringBuilder reverse = new StringBuilder ();
24
- reverse .append (original );
21
+ public static String LPS (String original ) throws IllegalArgumentException {
22
+ StringBuilder reverse = new StringBuilder (original );
25
23
reverse = reverse .reverse ();
26
24
return recursiveLPS (original , reverse .toString ());
27
25
}
Original file line number Diff line number Diff line change
1
+ package test ;
2
+
3
+ import static org .junit .jupiter .api .Assertions .*;
4
+
5
+ import org .junit .jupiter .api .Test ;
6
+
7
+ class LongestPalindromicSubsequenceTests {
8
+
9
+ @ Test
10
+ void test1 () {
11
+ assertEquals (LongestPalindromicSubsequence .LPS ("" ), "" );
12
+ }
13
+
14
+ @ Test
15
+ void test2 () {
16
+ assertEquals (LongestPalindromicSubsequence .LPS ("A" ), "A" );
17
+ }
18
+
19
+ @ Test
20
+ void test3 () {
21
+ assertEquals (LongestPalindromicSubsequence .LPS ("BABCBAB" ), "BABCBAB" );
22
+ }
23
+
24
+ @ Test
25
+ void test4 () {
26
+ assertEquals (LongestPalindromicSubsequence .LPS ("BBABCBCAB" ), "BABCBAB" );
27
+ }
28
+
29
+ @ Test
30
+ void test5 () {
31
+ assertEquals (LongestPalindromicSubsequence .LPS ("AAAAAAAAAAAAAAAAAAAAAAAA" ), "AAAAAAAAAAAAAAAAAAAAAAAA" );
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments