File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,20 @@ def get_failure_array(pattern):
53
53
return failure
54
54
55
55
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
+
56
70
if __name__ == "__main__" :
57
71
# Test 1)
58
72
pattern = "abc1abc12"
Original file line number Diff line number Diff line change 1
1
"""
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
3
3
4
4
For given string this algorithm computes value for each index,
5
5
which represents the maximal length substring starting from the index
You can’t perform that action at this time.
0 commit comments