Skip to content

Commit fa0e8b7

Browse files
committed
fix bug in _move_by_good_suffix()
1 parent faeac02 commit fa0e8b7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

python/33_bm/bm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _move_by_good_suffix(bad_character_index: int, suffix: List[int], prefix: Li
4343
# Test from k - 1
4444
for r, can_match_prefix in enumerate(reversed(prefix[:k]), bad_character_index + 2):
4545
if can_match_prefix: return r
46-
return len(suffix) + 1
46+
return len(suffix)
4747

4848

4949
def bm(s: str, pattern: str,) -> int:
@@ -70,4 +70,8 @@ def bm(s: str, pattern: str,) -> int:
7070

7171
s = "Here is a simple example"
7272
pattern = "example"
73-
print(bm(s, pattern))
73+
print(bm(s, pattern))
74+
75+
s = "abcdcccdc"
76+
pattern = "cccd"
77+
print(s.find(pattern) == bm(s, pattern))

0 commit comments

Comments
 (0)