标签:div nbsp substring code lin || == 动态 return
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); } };
5. Longest Palindromic Substring
标签:div nbsp substring code lin || == 动态 return
原文地址:https://www.cnblogs.com/ymjyqsx/p/10524738.html