mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-30 14:13:44 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
23a99c859d
commit
6fb609b07d
|
@ -1,5 +1,6 @@
|
|||
# https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
|
||||
|
||||
|
||||
def knuth_morris_pratt(text: str, pattern: str) -> list[int]:
|
||||
"""
|
||||
Knuth-Morris-Pratt (KMP) string search algorithm in Python.
|
||||
|
@ -19,6 +20,7 @@ def knuth_morris_pratt(text: str, pattern: str) -> list[int]:
|
|||
[]
|
||||
|
||||
"""
|
||||
|
||||
def build_prefix_table(pattern: str) -> list[int]:
|
||||
"""
|
||||
Build the prefix table for the given pattern.
|
||||
|
@ -60,6 +62,7 @@ def knuth_morris_pratt(text: str, pattern: str) -> list[int]:
|
|||
j = prefix_table[j - 1]
|
||||
return positions
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
text = input("Enter the text: ")
|
||||
pattern = input("Enter the pattern to search for: ")
|
||||
|
|
Loading…
Reference in New Issue
Block a user