2026-01-11 08:25:47 +0300 MSK
Shortest Palindrome
Links
Code
class Solution:
def shortestPalindrome(self, s: str) -> str:
length = len(s)
reversed_string = s[::-1] # Reverse the string
for i in range(length):
if s[: length - i] == reversed_string[i:]:
return reversed_string[:i] + s
return ""