class Solution {
public:
string longestPalindrome(string s) {
// dp[i][j]表示以s[i...j]是否为回文子串
int n = s.size();
int res = 1;
int start = 0;
vector<vector<bool>> dp(n,vector<bool>(n,true));
for(int j=1;j<n;j++){
for(int i=j-1;i>=0;i--){
if(s[i]==s[j]){
dp[i][j] = dp[i+1][j-1];
}else{
dp[i][j] = false;
}
if(dp[i][j]){
if(j-i+1>res){
res = j-i+1;
start = i;
}
}
}
}
return s.substr(start,res);
}
};