mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-30 22:23:42 +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
|
# https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
|
||||||
|
|
||||||
|
|
||||||
def knuth_morris_pratt(text: str, pattern: str) -> list[int]:
|
def knuth_morris_pratt(text: str, pattern: str) -> list[int]:
|
||||||
"""
|
"""
|
||||||
Knuth-Morris-Pratt (KMP) string search algorithm in Python.
|
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]:
|
def build_prefix_table(pattern: str) -> list[int]:
|
||||||
"""
|
"""
|
||||||
Build the prefix table for the given pattern.
|
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]
|
j = prefix_table[j - 1]
|
||||||
return positions
|
return positions
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
text = input("Enter the text: ")
|
text = input("Enter the text: ")
|
||||||
pattern = input("Enter the pattern to search for: ")
|
pattern = input("Enter the pattern to search for: ")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user