题解 | #公共子串计算#
公共子串计算
http://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b
let str1 = readline(), str2 = readline()
setStr1LessStr2()
findMaxLenSubStr()
function setStr1LessStr2() {
if (str1.length > str2.length) {
let temp = str1
str1 = str2
str2 = temp
}
}
function findMaxLenSubStr() {
for (let maxLen = str1.length; maxLen > 0; maxLen--) {
for (let start = 0; start + maxLen <= str1.length; start++) {
let subStr = str1.substr(start, maxLen)
if (str2.indexOf(subStr) > -1) {
print(subStr.length)
return
}
}
}
print(0)
}
// werasdfaswer
// rrr
// werasdfaswer
// z