(a, b)
return tmp[-2][-2]
最长公共子串
最长公共子串
最长公共子串
def lcs(a, b):
    """ 最长公共子串"""
    tmp = [[0]* (len(b)+1) for _ in range(len(a)+1)]
    for i in range(len(a)):
        for j in range(len(b)):
            if a[i] == b[j]:
                tmp[i][j] = tmp[i-1][j-1]+1
            else:
                tmp[i][j] = max(tmp[i][j-1], tmp[i-1][j])
    return tmp[-2][-2]
def lcs ( a , b ) : tmp = [ [ 0 ] * ( len ( b ) + 1 ) for _ in range ( len ( a ) + 1 ) ] for i in range ( len ( a ) ) : for j in range ( len ( b ) ) : if a [ i ] == b [ j ] : tmp [ i ] [ j ] = tmp [ i - 1 ] [ j - 1 ] + 1 else : tmp [ i ] [ j ] = max ( tmp [ i ] [ j - 1 ] , tmp [ i - 1 ] [ j ] ) return tmp [ - 2 ] [ - 2 ]