题解 | #最长重复子串#
最长重复子串
http://www.nowcoder.com/practice/4fe306a84f084c249e4afad5edf889cc
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* @param a string字符串 待计算字符串
* @return int整型
*/
function solve( a ) {
let n = a.length;
let res = 0;
for (let i = Math.floor(n / 2); i > 0; i--) {
let count = 0;
for (let j = 0; j < n - i; j++) {
if (a[j] == a[i + j]) {
count++;
} else {
count = 0;
}
if (count == i) return i * 2;
}
}
return res;
}
module.exports = {
solve : solve
};