class Solution {
public:
int strStr(string haystack, string needle) {
if (needle.empty()) return 0;
int j,k;
for (int i = 0; i <= (int)haystack.length() - (int)needle.length(); ++i) {
for (j = 0,k=i; j < needle.length(); ++j) {
if (k==haystack.length() || haystack[k] != needle[j])
break;
else {
++k;
}
}
if (j == needle.length())
return i;
}
return -1;
}
};