class Solution {
public:
int strStr(string haystack, string needle) {
int n = haystack.size(), m = needle.size();
for (int i = 0, j = 0; i + m <= n; ++i)
{
while (j < m && haystack[i + j] == needle[j])
j++;
if (j == m)
return i;
j = 0;
}
return -1;
}
};