class Solution {
public int strStr(String haystack, String needle) {
if(needle == null || needle.length() <= 0){
return 0;
}
int hlen = haystack.length();
int nlen = needle.length();
if(hlen < nlen){
return -1;
}
for(int i=0;i<=hlen-nlen;i++){
int j = 0;
while(haystack.charAt(i+j) == needle.charAt(j)){
j++;
if(j >= nlen){
return i;
}
}
}
return -1;
}
}
逻辑比较简单,就不细说了