题解 | #查找两个字符串a,b中的最长公共子串#
查找两个字符串a,b中的最长公共子串
https://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
暴力破解
let l1 = readline();
let l2 = readline();
let short = l1.length < l2.length ? l1 : l2;
let long = l1.length < l2.length ? l2 : l1;
let l = 0, res = '';
for(let i = 0; i < short.length; i++) {
for(let j = i; j < short.length; j++) {
let str = short.substring(i, j);
if(long.includes(str)) {
if(str.length > l) {
res = str;
l = res.length;
}
}
}
}
console.log(res);

SHEIN公司福利 778人发布