class Solution {
public:
string longestPalindrome(string s) {
vector<vector<int>> dp(s.size(),vector<int>(s.size(),0));
int res=0;
int l=0;
int r=0;
for(int i=s.size()-1;i>=0;i--){
for(int j=i;j<s.size();j++){
if(s[i]==s[j]){
if(j-i<=2){
dp[i][j]=1;
}
else if(dp[i+1][j-1]){
dp[i][j]=1;
}
}
if(dp[i][j]&&j-i+1>res){
res=j-i+1;
r=j;
l=i;
}
}
}
return s.substr(l,r-l+1);
}
};
//https://leetcode-cn.com/problems/longest-palindromic-substring/solution/5-zui-chang-hui-wen-zi-chuan-dong-tai-gu-3vfv/
Reference link:
When s[i]==s[j], if ji<=2, then dp[i][j]=1 If dp[i+1][j-1]=1, then the same dp[i] [j]=1