题解 | #回文字符串#

回文字符串

https://www.nowcoder.com/practice/84424799af474ba093b06c29a1f12dfb

  1. 比较第一个与最后一个,第二个与倒数第二个...
  2. 比较次数为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
}


全部评论

相关推荐

Yki_:你要算时间成本呀,研究生两三年,博士三四年,加起来就五六年了,如果你本科去腾讯干五年,多领五年的年薪,加上公司内涨薪,可能到时候十五年总薪资也跟博士差不多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务