privatestaticclassSolution{ public String longestPalindrome(String s){ int n = s.length(); boolean[][] memo = newboolean[n][n]; int begin = 0; int end = 0; int max = -1; for (int i = 0; i < n; i++) { memo[i][i] = true; } for (int j = 0; j < n; j++) { for (int i = 0; i < j; i++) { if (j - i == 1 && s.charAt(i) == s.charAt(j)) { memo[i][j] = true; } elseif (j - i >= 2) { memo[i][j] = memo[i + 1][j - 1] && s.charAt(i) == s.charAt(j); } if (j - i > max && memo[i][j]) { max = j - i; begin = i; end = j; } } }