@@ -0,0 +1,843 @@
+public class RabinKarp %7B%0A%0A%09private static final int BASE = 101;%0A%09private static final int MOD = 1_000_007;%0A%0A%09private static int hash(String pattern) %7B%0A%09%09int hashCode = 0;%0A%09%09for (int i = 0; i %3C pattern.length(); i++)%0A%09%09%09hashCode += (pattern.charAt(i) * Math.round(Math.pow(BASE,%0A%09%09%09%09%09pattern.length() - i)))%0A%09%09%09%09%09%25 MOD;%0A%09%09return hashCode;%0A%09%7D%0A%0A%09private static int rabinKarp(String s, String pattern) %7B%0A%09%09int hpattern = hash(pattern);%0A%09%09int hs = hash(s.substring(0, pattern.length()));%0A%09%09for (int i = 0; i %3C s.length() - pattern.length(); i++) %7B%0A%09%09%09if (hs == hpattern)%0A%09%09%09%09if (s.substring(i, i + pattern.length()).equals(pattern))%0A%09%09%09%09%09return i;%0A%09%09%09hs = hash(s.substring(i + 1, i + 1 + pattern.length()));%0A%09%09%7D%0A%09%09return -1;%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09System.out.println(rabinKarp(%22ABC ABCDAB ABCDABCDABDE%22, %22ABCDABD%22));%0A%09%7D%0A%0A%7D%0A

Create RabinKarp.java