class Solution { public: string longestPalindrome(string s) { if (s.size() <= 1){ return s; } int a = 0; //记录临时值 int length = 0; int ta = 1; //滑动窗口边界 int tb = 0; int t = 0; bool flag = false; //匹配标记 const char* p = s.c_str(); for(int i=0;i<s.size();i++){ for(int j = i + length;j<s.size();j++){ t = (j-i+1); tb = t/2; for(int k =i;k<(i+tb);k++){ if (p[k] != p[j - k + i]) { flag = true; break; } } if (!flag){ if (t > length){ a = i; length = t; } } flag = false; } } if (a == 0 && length == 0) { length = 1; } return s.substr(a,length); } };