1
class Solution:
2
def shortestPalindrome(self, s: str) -> str:
3

4
end = 0
5

6
# if the string itself is a palindrome return it
7
if s == s[::-1]:
8
return s
9

10
# Otherwise find the end index of the longest palindrome that starts
11
# from the first character of the string
12

13
for i in range(len(s) + 1):
14
if s[:i] == s[:i][::-1]:
15
end = i - 1
16

17
# return the string with the remaining characters other than
18
# the palindrome reversed and added at the beginning
19

20
return (s[end + 1 :][::-1]) + s

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0