https://leetcode.com/problems/longest-palindromic-substring/description/
代码:
class Solution {
public String longestPalindrome(String s) {
if(s == null && s.length() == 0) return null;
int len = s.length();
boolean[][] dp = new boolean[len][len];
String res="";
for (int i = len - 1 ; i >= 0; i--){
for(int j = i; j < len; j++){
if(s.charAt(i) == s.charAt(j) && (j - i < 3 || dp[i+1][j-1])){
dp[i][j] = true;
if(j - i + 1 > res.length())
res = s.substring(i,j+1);
}
}
}
return res;
}
}
网友评论