题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param A string字符串 * @return int整型 */ int getLongestPalindrome(string A) { int n, sub=1, mx = 1; int d = 0; for (int i=0; i < A.size()-1; i++) { n = A.size() - 1; while (i != n) { if (A[i] == A[n]) { do { d++; } while ((A[i + d] == A[n - d]) && (i + d) < (n - d)); if (A[i + d] == A[n - d]) sub = n - i + 1; } d = 0; mx = max(sub, mx); n--; } } return mx; } };笨方法qaq