#去哪儿旅行秋招# function isPalindrome(str){ let reser = str.split('').reverse().join('') return reser === str } function find(arrs,n,m){ let myMap = new Map() for(let i = 0;i myMap.set(arrs[i],i+1) } let res = []; function backtracking(index,curstr,used){ if(index === arrs.length){ if(isPalindrome(curstr)){ res.push({pal:curstr}) } return; } for(let i= 0;i if(used[i]) continue; let newstr = curstr + arrs[i]; let newused = [...used] newused[i] = true; backtracking(index+1,newstr,newused) if(newstr.length let mid = Math.floor(newstr.length/2); let temp = newstr.slice(0,mid)+arrs[i]+newstr.slice(mid); backtracking(index+1,temp,newstr) } } } let initused = new Array(arrs.length).fill(false); backtracking(0,'',initused) let orderanswer = []; for(let i = 0;i let nstr = res[0].pal.substring(i,i+m); let or = myMap.get(nstr) orderanswer.push(or) } // console.log(orderanswer) return orderanswer.join(' ') let result = find(arr,n,m) console.log(result)#去哪儿网25前端笔试#