第三题,最简单暴力解,连缓存都没用,可以过 const readline = require('readline') const log = console.log.bind(console) const rl = readline.createInterface({ input: process.stdin, output: process.stdout }) rl.on('line', function(line){ const str = line.trim() const result = handle(str) // var output = result ? 1 : 0 log(result) }); const valid = function(checkString) { var s = checkString var len = s.length var odd = len % 2 === 1 var subLen = Math.floor(len / 2) var t1 = s.slice(0, subLen) var t2 = odd ? s.slice(subLen + 1) : s.slice(subLen) t2 = t2.split('').reverse().join('') // log('t', t1, t2) return t1 === t2 } const handle = function(str) { var s = str var arr = s.split('') var set = new Set(arr) set = [...set] var result = 0 for(var k = 0; k < set.length; k++) { var c = set[k] var t = c + s if (valid(t)) { return 1 } } for(var i = 0; i < s.length; i++) { for(var j = 0; j < set.length; j++) { var v = set[j] var temp = s.slice(0, i + 1) + v + s.slice(i + 1) if (valid(temp)) { return 1 } } } return 0 } btw,前端为何不用node(
点赞 2

相关推荐

点赞 评论 收藏
分享
白菜小丑呜呜:Radis写错了兄弟
点赞 评论 收藏
分享
牛客网
牛客企业服务