I tried few variations. This one was accepted. I can probably reduce the number of comparisons even further. Any suggestions would be more than welcome. Thanks

```
public int strStr(String haystack, String needle) {
if (needle.length() == 0) return 0;
if (needle.length() > haystack.length()) return -1;
int j = 0;
for (int i = 0; i < haystack.length(); i++) {
if (haystack.charAt(i) == needle.charAt(j)) {
j++;
if ( j == needle.length()) return (i - j +1);
}
else {
i = i - j;
j = 0;
}
}
return -1;
}
```