s | result |
---|---|
"abcdcba" | 7 |
"abacde" | 3 |
: 이중포문으로 인덱스를 옮겨가며 팰린드롬 체크.
팰린드롬 => 현재 문자열 == 거꾸로한 문자열
def check(s):
if s == s[::-1]: return True
return False
def solution(s):
l = -1e9
for i in range(len(s)):
for j in range(i, len(s)+1):
if check(s[i:j]):
l = max(l, len(s[i:j]))
return l