3
string longestPalindrome(string s) {4
if (s.size() <= 1) return s;8
for (int i = 0; i < s.size(); i++) {9
string sub1 = expand(s, i, i + 1);10
string sub2 = expand(s, i, i);12
string sub3 = sub1.size() > sub2.size() ? sub1 : sub2;14
if (sub3.size() > longest.size()) {21
string expand(string s, int i, int j) {22
while (j < s.size() && i >= 0 && s[i] == s[j]) {26
// Add 1 to i and subtract 1 from j because the range is expanded by 1 on27
// each side before it ends28
return s.substr(i + 1, j - i - 1);