思路
找一个字符串中是否包含另一个字符串,并返回其位置。按照复杂的做那么就是KMP
class Solution {
public:
int strStr(string haystack, string needle) {
int i = -1,len1 = haystack.size(),len2 = needle.size();
while(++i <= len1-len2){
string tem = haystack.substr(i,len2);
if(tem == needle)
return i;
}
return -1;
}
};