public String longestPalindrome(String s) {
String rs = "";
int res = 0;
for(int i = 0; i< s.length(); i++){
int left = i, right = i;
while(left >= 0 && s.charAt(i) == s.charAt(left)) left --;
while(right < s.length() && s.charAt(i) == s.charAt(right)) right ++;
while (left >= 0 && right < s.length()){
if (s.charAt(left) != s.charAt(right))
break;
left --; right ++ ;
}
if(right - left - 1 > res){
res = right - left - 1;
rs = s.substring(left+1, right);
}
}
return rs;
}