Solución
solution.tsTypeScript
export function longestPalindrome(s: string): string {
let bestCandidate = ''
function expand(left: number, right: number): string {
// Expand while inside bounds and left/right charactes match
while (left >= 0 && right < s.length&& s[left] === s[right]) {
left--
right++
}
return s.slice(left + 1, right)
}
for (let i = 0; i < s.length; i++) {
const odd = expand(i, i)
const even = expand(i, i + 1)
if (odd.length > bestCandidate.length) bestCandidate = odd
if (even.length > bestCandidate.length) bestCandidate = even
}
return bestCandidate;
}0respuestas