Skip to content

Commit 72d7ee9

Browse files
committed
Fix algoirthm reference link
1 parent d2f4f05 commit 72d7ee9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

strings/knuth_morris_pratt.py

+14
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ def get_failure_array(pattern):
5353
return failure
5454

5555

56+
def prefix_function(input_string: str) -> list:
57+
prefix_result = [0] * len(input_string)
58+
59+
for i in range(1, len(input_string)):
60+
j = prefix_result[i - 1]
61+
while j > 0 and input_string[i] != input_string[j]:
62+
j = prefix_result[j - 1]
63+
if input_string[i] == input_string[j]:
64+
j += 1
65+
prefix_result[i] = j
66+
67+
return prefix_result
68+
69+
5670
if __name__ == "__main__":
5771
# Test 1)
5872
pattern = "abc1abc12"

strings/z_function.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
https://cp-algorithms.com/string/z-function.html#:~:text=The%20Z%2Dfunction%20for%20this,Note.
2+
https://cp-algorithms.com/string/z-function.html
33
44
For given string this algorithm computes value for each index,
55
which represents the maximal length substring starting from the index

0 commit comments

Comments
 (0)