728x90
SMALL
def is_palindrome(s):
left, right = 0, len(s)-1
while left < right:
if s[left] != s[right]:
return False
left += 1
right -= 1
return True
s = input()
print('true' if is_palindrome(s) else 'false')
- 단순 문자열 비교(s == s[::-1])로도 간단히 풀 수 있는 문제이지만, Two Pointer 기법으로 조금 더 효율적으로 풀게 되었습니다.
728x90
LIST
'알고리즘 문제 > 랜덤 마라톤 (solved.ac)' 카테고리의 다른 글
🥈 22935번: 이진 딸기 (0) | 2024.07.05 |
---|---|
🥈 25193번: 곰곰이의 식단 관리 (0) | 2024.07.04 |
🥈 26085번: 효구와 호규 (Easy) (0) | 2024.07.02 |
🥈 19621번: 회의실 배정 2 (0) | 2024.06.29 |
🥈 4096번: 팰린드로미터 (1) | 2024.06.28 |