题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af
class Solution { public: int getLongestPalindrome(string A) { size_t len = A.size(); int left = 0; int right = 0; int retlen = 0; //偶数 for(int i = 0;i < len; i++) { left = i; right = i + 1; while(left >= 0 && right < len && A[left] == A[right]) { left--; right++; } retlen = max(retlen ,right - left - 1); } //奇数 for(int j = 0;j < len;j++) { left = j; right = j; while(left >= 0 && right < len && A[left] == A[right]) { left--; right++; } retlen = max(retlen ,right - left - 1); } return retlen ; } };