public static string LongestPalindrome(string s){int max = 1;//串长度int index = 0, ind = 1, indB = 0, indF = 0;if (s == null || s.Length <= 1) return s;string s1 = s.Substring(0, 1);//结果串for (; index < s.Length - 1; index++){for (ind = index + 1; ind < s.Length; ind++){bool isequal = (s[index] == s[ind]);if (isequal && (ind - index - 1) % 2 == 1){int indM = (ind + index) / 2; //11 + 7 / 2 中点 9indB = indM - 1; //9 - 1 = 8indF = indM + 1; //9 + 1 = 10while (indB >= index){if (s[indB] == s[indF]){int _max = indF - indB + 1; //10 - 8 + 1 = 3 长度if (_max > max){//更新max = _max;s1 = s.Substring(indB, _max);}indB--;indF++;}else{indB = index - 1;}}}if (isequal && (ind - index - 1) % 2 == 0){indB = (index + ind) / 2; // 8 + 9 / 2 = 8indF = (index + ind) / 2 + 1;// 8 + 9 / 2 + 1 = 9while (indB >= index){if (s[indB] == s[indF]){int _max = indF - indB + 1; //9 - 8 + 1 = 2 长度if (_max > max){//更新max = _max;s1 = s.Substring(indB, _max);}indB--;indF++;}else{indB = index - 1;}}}}}return s1;}