题目
实现一个字符串 indexOf()的功能。class Solution {
public:
int next[100005];
int strStr(string haystack, string needle) {
if(needle=="")
return 0;
return KMP(haystack,needle);
}
int KMP(string content,string str)
{
getNext(str);
int i=0,j=0;
while(i=str.length())
{
return i-str.length();
}
else
return -1;
}
void getNext(string str)
{
next[0]=0;
for(int i=1;i
};
把看毛片算法又温习了一遍。KMP faster than 94% c++ submissions.