一、28. 找出字符串中第一个匹配项的下标
模式串匹配也不难,就是时间复杂度多一些。
class Solution {
public:
int strStr(string haystack, string needle) {
//试试模式串匹配
int a =haystack.size();
for(int i=0;i<haystack.size();i++){
for(int j=0;j<needle.size();j++){
if(haystack[j+i] != needle[j] ){
break;
}else{
if(j == needle.size()-1){
return i;
}
continue;
}
}
}
return -1;
}
};
一刷KMP暂时过了,全心复试