Problem:
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Solution:class Solution {
public:
int strStr(string haystack, string needle) {
if (haystack.size() < needle.size()) return -1;
int j = -1;
for (int i = 0; i <= haystack.size() - needle.size(); i++){
string s = haystack.substr(i, needle.size());
if (s == needle){
j = i;
break;
}
}
return j;
}
};