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