Update kmp.cpp
This commit is contained in:
parent
a4913b1056
commit
483cef11c1
|
@ -1,4 +1,4 @@
|
||||||
int KMP(string &S, string &T) {
|
int kmp(string &S, string &T) {
|
||||||
// Generate KMP table
|
// Generate KMP table
|
||||||
vector<int> F(T.length() + 1, 0);
|
vector<int> F(T.length() + 1, 0);
|
||||||
F[0] = -1;
|
F[0] = -1;
|
||||||
|
@ -14,6 +14,11 @@ int KMP(string &S, string &T) {
|
||||||
if (S[i] == T[j]) {
|
if (S[i] == T[j]) {
|
||||||
i++, j++;
|
i++, j++;
|
||||||
if (j == T.length()) return i - j; // Found match
|
if (j == T.length()) return i - j; // Found match
|
||||||
|
/*if (j == T.size()) {
|
||||||
|
ret++; // Count matches
|
||||||
|
j = F[j];
|
||||||
|
if (j < 0) i++, j++;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
j = F[j];
|
j = F[j];
|
||||||
|
|
Loading…
Reference in a new issue