[ Python ] KMP Algorithms

Posted coder211

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[ Python ] KMP Algorithms相关的知识,希望对你有一定的参考价值。

 1 def pmt(s):
 2     """
 3     :param s: the string to get its partial match table
 4     :return: partial match table
 5     """
 6     prefix = [s[:i + 1] for i in range(len(s) - 1)]
 7     suffix = [s[i + 1:] for i in range(len(s) - 1)]
 8     intersection = set(prefix) & set(suffix)
 9     if intersection:
10         return len(max(intersection))
11     else:
12         return 0
13 
14 def kmp(source, target):
15     for i in range(len(source)):
16         pass

 

以上是关于[ Python ] KMP Algorithms的主要内容,如果未能解决你的问题,请参考以下文章