Speed 1x
for i in range(N - M + 1):
j = 0
while(j < M):
if (txt[i + j] != pat[j]):
break
j += 1
if (j == M):
return i
Moving the needle offset pointer along to the next position in the haystack.