Last active
June 20, 2020 15:15
-
-
Save prkagrawal/bcb74f9f0f5a95c3fa0413de7d2269a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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