Skip to content

Commit 91e24c2

Browse files
committed
substring search brute force minor fix
1 parent 7daf905 commit 91e24c2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

substring-search/brute_force.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
# m - length of the text
55
# n - length of pattern
66
def search(text: str, pattern: str) -> int:
7-
7+
8+
t:int = 0
89
last_index: int = len(text) - len(pattern) + 1
9-
for t in range(last_index):
10+
11+
while t <= len(text) - len(pattern):
1012
p:int = 0
1113
while p < len(pattern):
1214
if text[t + p] != pattern[p]:
@@ -16,6 +18,7 @@ def search(text: str, pattern: str) -> int:
1618
if p == len(pattern):
1719
return t
1820
t += 1
21+
1922
return -1
2023

2124

0 commit comments

Comments
 (0)