https://blog.csdn.net/q547550831/article/details/51860017
链接
class Solution {
public:
int strStr(string haystack, string needle) {
int n=haystack.size();
int m=needle.size();
unordered_map<char,int> dd;
for(int i=0;i<m;i++){
dd[needle[i]]=m-i;
}
int s=0;
while(s<=n-m){
if(haystack.substr(s,m)==needle) return s;
else{
if(s+m>n-1) return -1;
if(dd.find(haystack[s+m])!=dd.end()){
s+=dd[haystack[s+m]];
}
else{
s+=m+1;
}
}
}
return -1;
}
};