param { string } s return { string } var LongestPalindrome = function ( s ) : string { if ( s . length === 0 || s . length === 1 ) { return s ; } let max = 0 ; let arr = [ ] ; let result = '' ; for ( let i = 0 ; i < s . length ; i ++ ) { arr [ i ] = [ ] ; } for ( let right = 1 ; right < s . length ; right ++ ) { for ( let left = 0 ; left < right ; left ++ ) { if ( s . charAt ( left ) === s . charAt ( right ) && ( right - left <= 2 || arr [ left + 1 ] [ right - 1 ] === true ) ) { arr [ left ] [ right ] = true ; if ( right - left + 1 > max ) { max = right - left + 1 ; result = s . slice ( left , right + 1 ) ; } } } } if ( max === 0 ) { result = s [ 0 ] ; } return result ; } ; export { LongestPalindrome } ;