Skip to content

Commit bfcd6de

Browse files
William FisetWilliam Fiset
William Fiset
authored and
William Fiset
committed
Boyer-Moore tweak
1 parent 6d8bb42 commit bfcd6de

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/com/williamfiset/algorithms/strings/BoyerMooreStringSearch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public List<Integer> findOccurrences(String text, String pattern) {
3535

3636
int n = pattern.length();
3737
for (int textIndex = n - 1, patternIndex = n - 1; textIndex < text.length(); ) {
38+
// Found a match!
3839
if (patternIndex >= 0 && pattern.charAt(patternIndex) == text.charAt(textIndex)) {
3940
if (patternIndex == 0) {
4041
occurrences.add(textIndex);
@@ -43,7 +44,7 @@ public List<Integer> findOccurrences(String text, String pattern) {
4344
}
4445
patternIndex--;
4546
} else {
46-
textIndex += n - min(max(patternIndex, 0), 1 + skipTable[text.charAt(textIndex)]);
47+
textIndex += n - min(max(patternIndex, 0), skipTable[text.charAt(textIndex)] + 1);
4748
patternIndex = n - 1;
4849
}
4950
}

0 commit comments

Comments
 (0)