题解 | #公共子串计算#
公共子串计算
https://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
// Write your code here
// while(line = await readline()){
// let tokens = line.split(' ');
// let a = parseInt(tokens[0]);
// let b = parseInt(tokens[1]);
// console.log(a + b);
// }
let line1 = await readline();
let line2 = await readline();
let maxlen=0
for (let i = 0; i < line1.length; i++) {
for (let j = 0; j < line2.length; j++) {
if(line1[i]==line2[j]){
// console.log(line1[i],line2[j])
let end1=i;
let end2=j
let len=0
while(line1[end1]==line2[end2]&&end1<line1.length&&end2<line2.length){
len+=1
end1++
end2++
}
maxlen=Math.max(maxlen,len)
}
}
}
console.log(maxlen)
})();
查看12道真题和解析