我正在寻找一些文档,解释如何在JavaScript中完成最长回文算法的逻辑。我在SO上发现的内容在JS上很少,而在其他语言上很长。
Elsewhere, I have read about brute force, but not sure if thats the way to go. Then I have seen blogs on using a helper function called expand
. I have also seen some use the substring()
method. All the information out there has only served to confuse me in regards to what I am supposed to be going for, as a result, this is as far as I have gotten:
const solve = (strArray) => {
const reversed = strArray.split('').reverse().join('');
return;
}
我不知道这从一开始就是有缺陷的,还是我可以继续从这里开始构建。
I imagine I am iterating over reversed
and doing a comparison if reversed
is a certain length
, but comparison with what?