We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7daf905 commit 91e24c2Copy full SHA for 91e24c2
substring-search/brute_force.py
@@ -4,9 +4,11 @@
4
# m - length of the text
5
# n - length of pattern
6
def search(text: str, pattern: str) -> int:
7
-
+
8
+ t:int = 0
9
last_index: int = len(text) - len(pattern) + 1
- for t in range(last_index):
10
11
+ while t <= len(text) - len(pattern):
12
p:int = 0
13
while p < len(pattern):
14
if text[t + p] != pattern[p]:
@@ -16,6 +18,7 @@ def search(text: str, pattern: str) -> int:
16
18
if p == len(pattern):
17
19
return t
20
t += 1
21
22
return -1
23
24
0 commit comments