class Solution {
public:
int strStr(string haystack, string needle) {
if (haystack.empty() && needle.empty()) {
return 0;
}
if (haystack.empty()) {
return -1;
}
if (needle.empty()) {
return 0;
}
int s1 = haystack.length(), s2 = needle.length();
for (int i = 0; i < s1; i++) {
if (haystack[i] = needle[0] &&
haystack.substr(i, s2) == needle) {
return i;
}
}
return -1;
}
};