public class Solution
{
public String longestPalindrome(String s)
{
int len=s.length();
if(len==1)return s;
boolean dp[][]=new boolean[len][len];
for(int i=0;i<len;++i)dp[i][i]=true;
int maxlen=1;
int begin=0;
for(int L=2;L<=len;++L)
{
for(int i=0;i<len;++i)
{
int j=i+L-1;
if(j>=len)break;
if(s.charAt(i)==s.charAt(j))
{
if(L<=3)dp[i][j]=true;
else dp[i][j]=dp[i+1][j-1];
}
else dp[i][j]=false;
if(dp[i][j]==true)
{
if(j-i+1>maxlen)
{
maxlen=j-i+1;
begin=i;
}
}
}
}
return s.substring(begin, begin+maxlen);
}
}