```
class Solution {
public:
string longestPalindrome(string s) {
int sLen=s.length();
int leftMost=0,rightMost=0;
int Start=0,End=0;
int i=0;
while(i<sLen){
Start=i;
do{
i++;
}while(i<sLen&&s[i]==s[Start]);
End=i-1;
while(Start-1>=0&&End+1<sLen&&s[Start-1]==s[End+1]){
Start--;
End++;
}
if(rightMost-leftMost<End-Start){
leftMost=Start;
rightMost=End;
}
}
return s.substr(leftMost,rightMost-leftMost+1);
}
};
```