题解 | #密码截取#没有用动态规划
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void (async function () { // Write your code here const isDuiChen = (str) => { let n = str.length; let mid = parseInt(n / 2); let str1 = str.slice(0, mid); let str2; if (n % 2 !== 0) str2 = str.slice(mid + 1, n); else str2 = str.slice(mid, n); let m = str1.length; let i = 0; for (let j = m - 1; j >= 0; j--) { if (str1[i] !== str2[j]) break; i++; } return i === m ? true : false; }; while ((line = await readline())) { let n = line.length; let mid = parseInt(n / 2); if (n === 1) { console.log(1); } else { let result = 1; for (let temp = n; temp >= 2; temp--) { for (let i = 0; i < n - 1; i++) { if (i + temp > n) break; let str = line.slice(i, i + temp); if (isDuiChen(str)) { result = temp; break; } } if (result !== 1) break; } console.log(result); } } })();