File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- package DynamicProgramming ;
1+ package test ;
22import java .lang .*;
33import java .io .*;
44import java .util .*;
55
66/**
7- * @author Matteo Messmer https://github.com/matteomessmer
87 * Algorithm explanation https://www.educative.io/edpresso/longest-palindromic-subsequence-algorithm
98 */
109public class LongestPalindromicSubsequence {
@@ -19,9 +18,8 @@ public static void main(String[] args) {
1918 System .out .println (b + " => " + bLPS );
2019 }
2120
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 );
2523 reverse = reverse .reverse ();
2624 return recursiveLPS (original , reverse .toString ());
2725 }
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