Skip to content

Commit

Permalink
substring search brute force minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmmarkovic committed Mar 21, 2021
1 parent 7daf905 commit 91e24c2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions substring-search/brute_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# m - length of the text
# n - length of pattern
def search(text: str, pattern: str) -> int:


t:int = 0
last_index: int = len(text) - len(pattern) + 1
for t in range(last_index):

while t <= len(text) - len(pattern):
p:int = 0
while p < len(pattern):
if text[t + p] != pattern[p]:
Expand All @@ -16,6 +18,7 @@ def search(text: str, pattern: str) -> int:
if p == len(pattern):
return t
t += 1

return -1


Expand Down

0 comments on commit 91e24c2

Please sign in to comment.