package leetcode;

/**
 * https://leetcode.com/problems/longest-palindromic-subsequence/
 */
public class Problem516 {
    public int longestPalindromeSubseq(String s) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem516 prob = new Problem516();
        System.out.println(prob.longestPalindromeSubseq("bbbab")); // 4
        System.out.println(prob.longestPalindromeSubseq("cbbd")); // 2
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -224,32 +224,1121 @@
     
-// TODO%0A        return 0
+return longestPalindromSubsequence(s, 0, %22%22, new HashMap%3C%3E());%0A    %7D%0A%0A    private static int longestPalindromSubsequence(String str, int idx, String accu,%0A                                                   Map%3CString, Integer%3E memo) %7B%0A        if (idx == str.length()) %7B%0A            if (isPalindrome(accu)) %7B%0A                return accu.length();%0A            %7D%0A            return 0;%0A        %7D%0A        String key = idx + %22%7C%22 + accu;%0A        if (memo.containsKey(key)) %7B%0A            return memo.get(key);%0A        %7D%0A        int max = 0;%0A        if (isPalindrome(accu)) %7B%0A            max = accu.length();%0A        %7D%0A        int a = longestPalindromSubsequence(str, idx + 1, accu, memo);%0A        int b = longestPalindromSubsequence(str, idx + 1, accu + str.charAt(idx), memo);%0A        max = Math.max(max, Math.max(a, b));%0A        memo.put(key, max);%0A        return max;%0A    %7D%0A%0A    private static boolean isPalindrome(String str) %7B%0A        for (int i = 0, j = str.length() - 1; i %3C= j; i++, j--) %7B%0A            if (str.charAt(i) != str.charAt(j)) %7B%0A                return false;%0A            %7D%0A        %7D%0A        return true
 ;%0A  
@@ -1427,24 +1427,26 @@
 oblem516();%0A
+//
         Syst
@@ -1505,16 +1505,18 @@
 ); // 4%0A
+//
         
@@ -1578,16 +1578,634 @@
 ); // 2%0A
+//        System.out.println(prob.longestPalindromeSubseq(%22abacadae%22)); // 5%0A        System.out.println(prob.longestPalindromeSubseq(%22euazbipzncptldueeuechubrcourfpftcebikrxhybkymimgvldiwqvkszfycvqyvtiwfckexmowcxztkfyzqovbtmzpxojfofbvwnncajvrvdbvjhcrameamcfmcoxryjukhpljwszknhiypvyskmsujkuggpztltpgoczafmfelahqwjbhxtjmebnymdyxoeodqmvkxittxjnlltmoobsgzdfhismogqfpfhvqnxeuosjqqalvwhsidgiavcatjjgeztrjuoixxxoznklcxolgpuktirmduxdywwlbikaqkqajzbsjvdgjcnbtfksqhquiwnwflkldgdrqrnwmshdpykicozfowmumzeuznolmgjlltypyufpzjpuvucmesnnrwppheizkapovoloneaxpfinaontwtdqsdvzmqlgkdxlbeguackbdkftzbnynmcejtwudocemcfnuzbttcoew%22)); // 159%0A
     %7D%0A%7D%0A

Update problem 516