标签:div ges substr longest col stp find turn code
中心扩展法。
class Solution { public: string longestPalindrome(string s) { int start = 0, end = 0; for (int i = 0; i < s.size(); ++i) { findLongest(s, i, i, start, end); findLongest(s, i, i + 1, start, end); } return s.substr(start, end - start + 1); } void findLongest(string s, int left, int right, int& start, int& end) { while (left >= 0 && right < s.size() && s[left] == s[right]) { --left; ++right; } left = left + 1; right = right - 1; if (right - left > end - start) { start = left; end = right; } } };
标签:div ges substr longest col stp find turn code
原文地址:https://www.cnblogs.com/ZSY-blog/p/12945987.html