Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 4, 2014 03:15
Show Gist options
  • Save globby/9339664 to your computer and use it in GitHub Desktop.
Save globby/9339664 to your computer and use it in GitHub Desktop.
An implementation of the Rabin-Karp algorithm
def RabinKarp(string, sub):
n, m = len(string), len(sub)
for i in range(0,n-m+1):
for j in range(0,m):
if string[i+j] != sub[j]:
break
else:
return i
return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment