《华为机试》刷题之HJ75 公共子串计算

阅读 31

2022-03-11

一、题目

在这里插入图片描述

二、示例

在这里插入图片描述

三、代码

while True:
    try:
        s1 = input()
        s2 = input()
        maxlength = 0
        for i in range(len(s1)):
            for j in range(i, len(s1)):
                if s1[i:j+1] in s2 and len(s1[i:j+1]) > maxlength:
                    maxlength = len(s1[i:j+1])
        print(maxlength)
    except:
        break

四、算法说明

无需啰嗦,暴力破解。

胡萝卜

2022年3月4日14:47:31

我不知道将去向何方,但我已在路上!
时光匆匆,虽未曾谋面,却相遇于斯,实在是莫大的缘分,感谢您的到访 !

精彩评论(0)

0 0 举报