Skip to content

Commit 30fd54c

Browse files
committed
speed
1 parent 78bb2b4 commit 30fd54c

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

algorithms/searching/kmp_search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
Pre: a string > substring.
1111
12-
Post: returns the first index where the substring was found.
12+
Post: returns a list of indices where the substring was found.
1313
1414
Time Complexity: O(n + k), where k is the substring to be found
1515
@@ -24,7 +24,7 @@ def search(string, word):
2424
word_length = len(word)
2525
prefix = compute_prefix(word)
2626
q = 0
27-
for i in range(len(string)):
27+
for i in xrange(len(string)):
2828
while q > 0 and word[q] != string[i]:
2929
q = prefix[q - 1]
3030
if word[q] == string[i]:
@@ -39,7 +39,7 @@ def compute_prefix(word):
3939
prefix = [0] * word_length
4040
k = 0
4141

42-
for q in range(1, word_length):
42+
for q in xrange(1, word_length):
4343
while k > 0 and word[k] != word[q]:
4444
k = prefix[k - 1]
4545

0 commit comments

Comments
 (0)