mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-11 07:07:15 +08:00
psf/black code formatting (#1277)
This commit is contained in:

committed by
Christian Clauss

parent
07f04a2e55
commit
9eac17a408
@ -7,23 +7,26 @@ Complexity : O(n*m)
|
||||
n=length of main string
|
||||
m=length of pattern string
|
||||
"""
|
||||
def naivePatternSearch(mainString,pattern):
|
||||
patLen=len(pattern)
|
||||
strLen=len(mainString)
|
||||
position=[]
|
||||
for i in range(strLen-patLen+1):
|
||||
match_found=True
|
||||
|
||||
|
||||
def naivePatternSearch(mainString, pattern):
|
||||
patLen = len(pattern)
|
||||
strLen = len(mainString)
|
||||
position = []
|
||||
for i in range(strLen - patLen + 1):
|
||||
match_found = True
|
||||
for j in range(patLen):
|
||||
if mainString[i+j]!=pattern[j]:
|
||||
match_found=False
|
||||
if mainString[i + j] != pattern[j]:
|
||||
match_found = False
|
||||
break
|
||||
if match_found:
|
||||
position.append(i)
|
||||
return position
|
||||
|
||||
mainString="ABAAABCDBBABCDDEBCABC"
|
||||
pattern="ABC"
|
||||
position=naivePatternSearch(mainString,pattern)
|
||||
|
||||
mainString = "ABAAABCDBBABCDDEBCABC"
|
||||
pattern = "ABC"
|
||||
position = naivePatternSearch(mainString, pattern)
|
||||
print("Pattern found in position ")
|
||||
for x in position:
|
||||
print(x)
|
||||
print(x)
|
||||
|
Reference in New Issue
Block a user