Skip to content

Commit 5ad0927

Browse files
committed
Update shortest-palindrome.py
1 parent fd896c8 commit 5ad0927

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: Python/shortest-palindrome.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ def shortestPalindrome(self, s):
2222

2323
A = s + s[::-1]
2424
prefix = self.getPrefix(A)
25-
26-
return s[prefix[-1]+1:][::-1] + s
25+
i = prefix[-1]
26+
while i > len(s) - 1:
27+
i = prefix[i]
28+
return s[i+1:][::-1] + s
2729

2830
def getPrefix(self, pattern):
2931
prefix = [-1] * len(pattern)

0 commit comments

Comments
 (0)