Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d80486f

Browse files
samay-rgbtrekhleb
andauthored
issue trekhleb#631 solved (trekhleb#809)
Co-authored-by: Oleksii Trekhleb <[email protected]>
1 parent 8c433f9 commit d80486f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/algorithms/string/knuth-morris-pratt/knuthMorrisPratt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ export default function knuthMorrisPratt(text, word) {
4343
if (text[textIndex] === word[wordIndex]) {
4444
// We've found a match.
4545
if (wordIndex === word.length - 1) {
46-
return (textIndex - word.length) + 1;
46+
return textIndex - word.length + 1;
4747
}
4848
wordIndex += 1;
4949
textIndex += 1;
5050
} else if (wordIndex > 0) {
5151
wordIndex = patternTable[wordIndex - 1];
5252
} else {
53-
wordIndex = 0;
53+
// wordIndex = 0;
5454
textIndex += 1;
5555
}
5656
}

0 commit comments

Comments
 (0)