https://www.cnblogs.com/grandyang/p/4464476.html
用动态规划做
class Solution { public: string longestPalindrome(string s) { if(s.empty()) return ""; int dp[s.size()][s.size()] = {0}; int left = 0,right = 0,len = 0; for(int i = 0;i < s.size();i++){ for(int j = 0;j < i;j++){ dp[j][i] = (s[i] == s[j]) && (i-j <= 2 || dp[j+1][i-1]); if(dp[j][i] && len < i - j + 1){ left = j; right = i; len = i - j + 1; } } } return s.substr(left,right - left + 1); } };