题解 | #查找两个字符串a,b中的最长公共子串#
查找两个字符串a,b中的最长公共子串
http://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
let s1 = readline();
let s2 = readline();
let left = 0;
right = 0;
let maxLen = 0;
let res = "";
let short = s1.length >= s2.length ? s2 : s1;
let long = s1.length >= s2.length ? s1 : s2;
while (right < short.length) {
let subStr = short.substring(left, right + 1);
while (!long.includes(subStr)) {
left++;
subStr = short.substring(left, right + 1);
}
if (right - left + 1 > maxLen) {
maxLen = right - left + 1;
res = subStr;
}
right++;
}
console.log(res);