We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 78bb2b4 commit 30fd54cCopy full SHA for 30fd54c
1 file changed
algorithms/searching/kmp_search.py
@@ -9,7 +9,7 @@
9
10
Pre: a string > substring.
11
12
- Post: returns the first index where the substring was found.
+ Post: returns a list of indices where the substring was found.
13
14
Time Complexity: O(n + k), where k is the substring to be found
15
@@ -24,7 +24,7 @@ def search(string, word):
24
word_length = len(word)
25
prefix = compute_prefix(word)
26
q = 0
27
- for i in range(len(string)):
+ for i in xrange(len(string)):
28
while q > 0 and word[q] != string[i]:
29
q = prefix[q - 1]
30
if word[q] == string[i]:
@@ -39,7 +39,7 @@ def compute_prefix(word):
39
prefix = [0] * word_length
40
k = 0
41
42
- for q in range(1, word_length):
+ for q in xrange(1, word_length):
43
while k > 0 and word[k] != word[q]:
44
k = prefix[k - 1]
45
0 commit comments