Skip to content

Commit 3e51f6b

Browse files
committed
Fix issue in KMP
1 parent caa4188 commit 3e51f6b

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎src/searching/knuth-morris-pratt.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
return i - j;
5959
}
6060
if (i < str.length && str[i] !== substr[j]) {
61-
if (table[j - 1] !== 0) {
61+
if (j > 0 && table[j - 1] !== 0) {
6262
j = table[j - 1];
6363
} else {
6464
i += 1;
@@ -73,3 +73,5 @@
7373
exports.kmp = kmp;
7474

7575
})(typeof window === 'undefined' ? module.exports : window);
76+
77+
exports.kmp('hello', 'll');

0 commit comments

Comments
 (0)