输出最长公共字符串长度-python实现
题目
输入:两个字符串,空格隔开,找公有字符串最长长度
输出:公共字符串长度
示例:
输入:abcdabcc abcdab
输出:6
def func():
a, b = input().split(" ")
if len(a) < len(b):
a, b = b, a
b_list_out = []
start_sign = 0
for i in range(1, len(b)+1):
c = b[start_sign:i]
if c in a:
b_list_out.append(len(c))
else:
start_sign = i - 1
b_list_out.sort()
if b_list_out:
print(b_list_out[-1])
else:
print(0)
if __name__ == '__main__':
func()