We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d431689 commit c6cf21eCopy full SHA for c6cf21e
1 file changed
DataStructures/Section12/BruteForce.py
@@ -0,0 +1,25 @@
1
+def brute_force(text, pattern):
2
+ l1 = len(text)
3
+ l2 = len(pattern)
4
+
5
+ i=0
6
+ j=0
7
8
+ flag = False
9
+ while i < l1:
10
+ j = 0
11
+ count = 0
12
+ while j < l2:
13
+ if i+j < l1 and text[i+j] == pattern[j]:
14
+ count += 1
15
+ j +=1
16
+ if count == l2:
17
+ print("\nPattern occurs at index ", i)
18
+ flag = True
19
+ i += 1
20
+ if not flag:
21
+ print('\nPattern is not at all present in the array')
22
23
24
+#Output of string matching with Brute force
25
+brute_force('acbcabccababcaacbcac','acbcac')
0 commit comments