@@ -0,0 +1,1269 @@
+package fundamentals.string.palindrome.lc516_longestpalindromicsubsequence;%0A%0Aimport org.junit.jupiter.api.Assertions;%0Aimport org.junit.jupiter.api.Test;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * Given a string s, find the longest palindromic subsequence's length in s.%0A */%0Apublic class Solution %7B%0A%0A    //    d  b  c  c  a  b%0A    // d %5B1, 1, 1, 2, 2, 4%5D%0A    // b %5B0, 1, 1, 2, 2, 4%5D%0A    // c %5B0, 0, 1, 2, 2, 2%5D%0A    // c %5B0, 0, 0, 1, 1, 1%5D%0A    // a %5B0, 0, 0, 0, 1, 1%5D%0A    // b %5B0, 0, 0, 0, 0, 1%5D%0A    @Test%0A    void test() %7B%0A        Assertions.assertEquals(4, longestPalindromeSubseq(%22dbccab%22));%0A    %7D%0A%0A    public int longestPalindromeSubseq(String s) %7B%0A        int n = s.length();%0A        int%5B%5D%5B%5D dp = new int%5Bn%5D%5Bn%5D;%0A        for (int i = n - 1; i %3E= 0; i--) %7B%0A            dp%5Bi%5D%5Bi%5D = 1; // Base case%0A            for (int j = i + 1; j %3C n; j++) %7B%0A                if (s.charAt(i) == s.charAt(j)) %7B%0A                    dp%5Bi%5D%5Bj%5D = dp%5Bi + 1%5D%5Bj - 1%5D + 2;%0A                %7D else %7B%0A                    dp%5Bi%5D%5Bj%5D = Math.max(dp%5Bi%5D%5Bj - 1%5D, dp%5Bi + 1%5D%5Bj%5D);%0A                %7D%0A            %7D%0A        %7D%0A        print(dp);%0A        return dp%5B0%5D%5Bn - 1%5D;%0A    %7D%0A%0A    private void print(int%5B%5D%5B%5D dp) %7B%0A        for (int%5B%5D row : dp) %7B%0A            System.out.println(Arrays.toString(row));%0A        %7D%0A    %7D%0A%0A%7D%0A

longest palindrome subsequence