题解 | #回文字符串#
回文字符串
https://www.nowcoder.com/practice/84424799af474ba093b06c29a1f12dfb
- 比较第一个与最后一个,第二个与倒数第二个...
- 比较次数为Math.floor(string.length / 2)
const _isPalindrome = (string) => { // 补全代码 let res for (let index = 0; index < Math.floor(string.length / 2); index++) { console.log(string[index], string[string.length - index - 1]) string[index] == string[string.length - index - 1] ? (res = true) : (res = false) } return res }