Content deleted Content added
change source to syntaxhighlight |
Booth's algorithm was wrong (tested it in my own code), so I replaced it with a correct version, including the fix from Booth himself https://www.cs.ubc.ca/~ksbooth/PUB/LCS.shtml |
||
Line 38:
<syntaxhighlight lang="python">
def least_rotation(S: str) -> int:
n = len(S)
▲ f = [-1] * len(S) # Failure function
▲ for j in range(1, len(S)):
▲ sj = S[j]
i = f[j - k - 1]
while i != -1 and
if
k = j - i - 1
i = f[i]
if
if
k = j
f[j - k] = -1
|