Skip to content

Instantly share code, notes, and snippets.

View rimijoker's full-sized avatar
🤓
Focusing

Anshuman Singh rimijoker

🤓
Focusing
View GitHub Profile
@rimijoker
rimijoker / Anshuman Singh GSoC 2020.md
Last active November 17, 2020 04:03
Google Summer of Code 2020(OpenMined) Final Work Product
@m00nlight
m00nlight / gist:daa6786cc503fde12a77
Last active March 7, 2024 09:23
Python KMP algorithm
class KMP:
def partial(self, pattern):
""" Calculate partial match table: String -> [Int]"""
ret = [0]
for i in range(1, len(pattern)):
j = ret[i - 1]
while j > 0 and pattern[j] != pattern[i]:
j = ret[j - 1]
ret.append(j + 1 if pattern[j] == pattern[i] else j)