06. 가장 긴 팰린드롬 문자열(leetcode: 5)
문제 분석
풀이
class Solution:
def longestPalindrome(self, s: str) -> str:
def expand(left, right):
while left >= 0 and right <= len(s) - 1 and s[left] == s[right]:
left -= 1
right += 1
return s[left + 1:right]
if len(s) < 2 or s == s[::-1]:
return s
ret = ''
for i in range(len(s)):
ret = max(ret,
expand(i, i + 1),
expand(i, i + 2),
key=len)
return retLast updated