题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
forloop双层循环闭眼算法,完整代码如下:
while (line = readline()) { let maxLen = 0; for (let i = 0; i < line.length; i++) { for (let j = i+1; j < line.length; j++) { let str = line.slice(i, j+1); if ( str == str.split('').reverse().join('') && str.length > maxLen) { maxLen = str.length; } } } console.log(maxLen); }