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 5a57fbb commit 618e83dCopy full SHA for 618e83d
substring-search/brute_force.py
@@ -0,0 +1,22 @@
1
+
2
3
+# O(m * n)
4
+# m - length of the text
5
+# n - length of pattern
6
+def search(text: str, pattern: str) -> int:
7
8
+ last_index: int = len(text) - len(pattern) + 1
9
+ for t in range(last_index):
10
+ p:int = 0
11
+ while p < len(pattern):
12
+ if text[t + p] != pattern[p]:
13
+ break
14
+ else:
15
+ p += 1
16
+ if p == len(pattern):
17
+ return t
18
+ t += 1
19
+ return -1
20
21
22
0 commit comments