Just wondering if Robin Karp was used for this just for introducing the algorithm, as finding just the first occurence can be done with O(n) as below:
public static int find(String str, String sub) {
int res = 0, curr = 0, offset = 0;
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i) == sub.charAt(curr)) {
if(curr + 1 == sub.length()) return i - offset - 1;
curr++;
offset++;
}
offset = 0;
}
return -1;
}