5
var longestPalindrome = function (s) {8
if (s.length === 1) return s;10
//the length of the palindrome is odd11
for (let index = 1; index < s.length - 1; index++) {12
if (s[index - 1] === s[index + 1]) {13
palindrome = s[index - 1] + s[index] + s[index + 1];14
for (let k = 1; index - 1 - k > -1 && index + 1 + k < s.length; k++) {15
if (s[index - 1 - k] === s[index + 1 + k]) {16
palindrome = s[index - 1 - k] + palindrome + s[index + 1 + k];22
if (palindrome.length > longestP.length) {23
longestP = palindrome;28
//the length of the palindrome is pair29
for (let index = 0; index < s.length - 1; index++) {30
if (s[index] === s[index + 1]) {31
palindrome = s[index] + s[index + 1];32
for (let k = 1; index - k > -1 && index + 1 + k < s.length; k++) {33
if (s[index - k] === s[index + 1 + k]) {34
palindrome = s[index - k] + palindrome + s[index + 1 + k];40
if (palindrome.length > longestP.length) {41
longestP = palindrome;