MCPcopy
hub / github.com/itcharge/AlgoNote / generateBadCharTable

Function generateBadCharTable

codes/python/04_string/string_sunday.py:19–25  ·  view source on GitHub ↗
(p: str)

Source from the content-addressed store, hash-verified

17# 生成后移位数表
18# bc_table[bad_char] 表示遇到坏字符可以向右移动的距离
19def generateBadCharTable(p: str):
20 m = len(p)
21 bc_table = dict()
22
23 for i in range(m): # 迭代到最后一个位置 m - 1
24 bc_table[p[i]] = m - i # 更新遇到坏字符可向右移动的距离
25 return bc_table
26
27print(sunday("abbcfdddbddcaddebc", "aaaaa"))
28print(sunday("abbcfdddbddcaddebc", "bcf"))

Callers 1

sundayFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected