最初解法
解题思路
双指针 依次移动,暴力双循环求解
代码
int strStr(string haystack, string needle) {
int size1=haystack.size(),size2=needle.size();
if(size2==0){return 0;}
int i=0,j=0,z=0;
while(i+j<size1){
z=i;
while(j<size2){
if(j==size2-1&&haystack[z]==needle[j]){
return i;
}
if(haystack[z]!=needle[j]){
i++;
j=0;
break;
}
else
{
z++;
j++;
}
}
}
return -1;
}