```
int strStr(string haystack, string needle) {
int n1 = haystack.length();
int n2 = needle.length();
if(n2==0)
return 0;
if(n2>n1)
return -1;
for(int i = 0;i < n1 - n2+1;i++)
{
for(int j = 0;j < n2;j++)
{
if(needle[j] != haystack[i+j])
break;
if(j+1 == needle.length())
return i;
}
}
return -1;
}
```