Skip to content

Instantly share code, notes, and snippets.

@prkagrawal
Last active June 20, 2020 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prkagrawal/bcb74f9f0f5a95c3fa0413de7d2269a7 to your computer and use it in GitHub Desktop.
Save prkagrawal/bcb74f9f0f5a95c3fa0413de7d2269a7 to your computer and use it in GitHub Desktop.
def stringPatternSearch(text,pattern):
n = len(text)
m = len(pattern)
count = 0
for i in range(n - m + 1):
for j in range(m):
if pattern[j] != text[i+j]:
break
if j == m-1 :
count = count + 1
print(count)
stringPatternSearch("lololo","lol") # 2
stringPatternSearch("lololol","lol") # 3
stringPatternSearch("lol","lol") # 1
stringPatternSearch("olooo","lol") # 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment