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