[LintCode]Longest Common Substring(Python)

来源:互联网 发布:同济大学软件学院电话 编辑:程序博客网 时间:2024/06/09 17:32
class Solution:    # @param A, B: Two string.    # @return: the length of the longest common substring.    def longestCommonSubstring(self, A, B):        # write your code here        maxlength = len(A) + 1        for i in range(maxlength)[::-1]:            substrB = []            for j in range(len(B) + 1 - i):                substrB.append(B[j: j + i])            for str in substrB:                if A.find(str) != -1:                    return i        return 0


原创粉丝点击