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