首页 > 度小满9.20前端笔试 算法题AK答案,JS写的,供学习使用
头像
xunuo
编辑于 2020-09-20 21:42
+ 关注

度小满9.20前端笔试 算法题AK答案,JS写的,供学习使用

1.涂色
function fn(own, need) {
  const arr1 = own.split('')
  const arr2 = need.split('')
  let ret = 0
  arr2.forEach(item => {
    const index = arr1.indexOf(item)
    if (index > -1) {
      ret++
      arr1[index] = null
    }
  })
  return ret
}
2.相似字符串
function fn(str) {
  if ((str.length % 3)) return false
  let lastStr = ''
  let tmp = ''
  for (let i = 0; i < str.length; i++) {
    tmp += str[i]
    if ( !((i + 1) % 3) && i ) {
      if (lastStr) {
        let num = 0
        for (let j = 0; j < 3; j++) {
          lastStr[j] !== tmp[j] && num++
        }
        if (num > 1) return false
      }
      lastStr = tmp
      tmp = ''
    }
  }
  return true
}


全部评论

(8) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐