二分思想
function solve( a ) { // write code here // 二分思想,如果存在重复子串m的话 2 * m < = a.length // 逐步递减 m 直到0 let maxLen = Math.floor(a.length / 2); while(maxLen > 0){ let start = 0; while(start <= a.length - maxLen * 2){ // 判断数组是否相同,相同直接返回,否则索引左移动 if(a.slice(start, start + maxLen) === a.slice(start + maxLen, start + maxLen * 2) ){ return maxLen * 2; } start++; } // 减少长度,再次寻找 maxLen--; } return maxLen; }