题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
const rl = require("readline").createInterface({ input: process.stdin }); rl.on('line', function(line) { let str = line let temp = '' let result = '' for(let i=0;i<str.length;i++) { temp = '' for(let j=i;j<str.length;j++) { temp+=str[j] if(temp.split('').reverse().join('')==temp&&temp.length>result.length) { result = temp } } } console.log(result.length) })
这个题的关键是1.回文子串的判断(反转前=反转后)2.从头到尾遍历字符,逐步增加字符长度去判断是否为回文子串