Update kmp.cpp

This commit is contained in:
Anthony Wang 2019-09-16 22:40:32 -05:00
parent a4913b1056
commit 483cef11c1

View file

@ -1,4 +1,4 @@
int KMP(string &S, string &T) {
int kmp(string &S, string &T) {
// Generate KMP table
vector<int> F(T.length() + 1, 0);
F[0] = -1;
@ -14,6 +14,11 @@ int KMP(string &S, string &T) {
if (S[i] == T[j]) {
i++, j++;
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 {
j = F[j];