public String longestPalindrome_dp2(String s) {

    int len = s.length();

    boolean[][] dp = new boolean[len][len];

    int start = 0;
    int end = 0;
    int max = 0;

    for (int i = s.length() - 1 ; i >= 0 ; i--) {
      for (int j = i ; j < s.length() ; j++) {
        if (s.charAt(i) == s.charAt(j) && (j - i < 2 || dp[i + 1][j - 1])) {

          dp[i][j] = true;

          if (j - i > max) {
            max = j - i;
            start = i;
            end = j;
          }
        }
      }
    }

    return s.substring(start, end + 1);
  }