class Solution {
public:
int strStr(string haystack, string needle) {
if(haystack.size()==0 || needle.size()==0)
return 0;
int res=-1,j=0;
for(int i=0;i<haystack.size() ;i++)
{
if(haystack[i]==needle[j])
{
int pre=i;
while(haystack[i]==needle[j]&&i<haystack.size()&& j<needle.size())
{
i++;j++;
}
if(j==needle.size())
return i-j;
else
{
j=0;i=pre;
}
}
}
return -1;
}
};
11-17
06-02