import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param A string字符串
* @return int整型
*/
public int getLongestPalindrome (String A) {
// write code here
if(A.length()==1){
return 1;
}
int max=0;
boolean dp[][] = new boolean[A.length()][A.length()];
for(int r=1;r<A.length();r++){
for(int l=0;l<=r;l++){
if(A.charAt(l)!=A.charAt(r)){
continue;
}
if(l==r){
dp[l][r] =true;
}else if(r-l<=2){
dp[l][r] = true;
}else{
dp[l][r] = dp[l+1][r-1];
}
if(dp[l][r]){
max = Math.max(max,r-l+1);
}
}
}
return max;
}
}
OJ---最长回文子串
最新推荐文章于 2025-05-24 10:42:46 发布