Notice
Recent Posts
Recent Comments
Link
S E P H ' S
[Python] 가장 긴 팰린드롬 본문
코딩테스트 연습 - 가장 긴 팰린드롬
앞뒤를 뒤집어도 똑같은 문자열을 팰린드롬(palindrome)이라고 합니다. 문자열 s가 주어질 때, s의 부분문자열(Substring)중 가장 긴 팰린드롬의 길이를 return 하는 solution 함수를 완성해 주세요. 예를들
programmers.co.kr
def isPalin(x):
if x == x[::-1]:
return True
def solution(s):
answer = 0
for i in range(len(s)):
for j in range(i+1, len(s)+1):
if isPalin(s[i:j]):
if answer < len(s[i:j]):
answer = len(s[i:j])
return answer
'Algorithm > Programmers' 카테고리의 다른 글
[Java] 2 x n 타일링 (0) | 2023.04.13 |
---|---|
[Python] n^2 배열 자르기 (0) | 2021.12.15 |
[Python] 기지국 설치 (0) | 2021.09.09 |
[Python] 숫자 게임 (0) | 2021.09.07 |
[Python] 스티커 모으기(2) (0) | 2021.09.07 |