Update
This commit is contained in:
parent
0069a6fa8e
commit
b23016b284
|
|
@ -15,10 +15,12 @@ public:
|
||||||
next[0] = -1;
|
next[0] = -1;
|
||||||
int j = -1;
|
int j = -1;
|
||||||
for(int i = 1; i < s.size(); i++){
|
for(int i = 1; i < s.size(); i++){
|
||||||
while(j >= 0 && s[i] != s[j+1])
|
while (j >= 0 && s[i] != s[j + 1]) {
|
||||||
j = next[j];
|
j = next[j];
|
||||||
if(s[i] == s[j+1])
|
}
|
||||||
|
if (s[i] == s[j + 1]) {
|
||||||
j++;
|
j++;
|
||||||
|
}
|
||||||
next[i] = j;
|
next[i] = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -37,7 +39,7 @@ public:
|
||||||
if (haystack[i] == needle[j + 1]) {
|
if (haystack[i] == needle[j + 1]) {
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
if (j == (needle.size() -1) ) {
|
if (j == (needle.size() - 1) ) {
|
||||||
return (i - needle.size() + 1);
|
return (i - needle.size() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue