You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
살짝 고민하면 문자열이 팰린드롬이 되도록 하는 다른 문자열을 찾는 방법을 생각해볼 수 있다.
즉, 문자열을 left, right로 나눴을 때 right가 팰린드롬이면 left의 역순을 오른쪽에 붙인 문자열이 팰린드롬이 될 것이다. 비슷하게 left가 팰린드롬이면 right의 역순을 왼쪽에 붙인 문자열이 팰린드롬이 될 것이고 이를 만족하는 문자열을 찾을 수 있다.
좀 더 파이썬하게 써보면 아래와 같다.
left + right + left[::-1]
right[::-1] + left + right
This discussion was converted from issue #29 on September 15, 2026 11:00.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/palindrome-pairs/
Problem Summary
문자열들이 주어질 때 팰린드롬이 되는 페어를 전부 구하는 문제.
Solution
단순 완전 탐색을 하면 시간 초과가 된다.
살짝 고민하면 문자열이 팰린드롬이 되도록 하는 다른 문자열을 찾는 방법을 생각해볼 수 있다.
즉, 문자열을 left, right로 나눴을 때 right가 팰린드롬이면 left의 역순을 오른쪽에 붙인 문자열이 팰린드롬이 될 것이다. 비슷하게 left가 팰린드롬이면 right의 역순을 왼쪽에 붙인 문자열이 팰린드롬이 될 것이고 이를 만족하는 문자열을 찾을 수 있다.
좀 더 파이썬하게 써보면 아래와 같다.
여기서 주의할 점은 빈 문자열이 있는데 이건 그냥 따로 처리해주면 된다.
Source Code
All reactions