题解 | #删除字符串中出现次数最少的字符#

删除字符串中出现次数最少的字符

https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})

rl.on('line',function(line){
  const map = new Map()
  for(let i=0;i<line.length;i++){
    if(!map.has(line[i])){
      map.set(line[i],1)
    }else{
      map.set(line[i],map.get(line[i]) + 1)
    }
  }
  const arr = line.split('')
  const numArr = []
  for(const item of map){
    numArr.push(item[1])
  }
  const n = Math.min(...numArr)
  const temp = []
  for(const item of map){
    if(item[1] === n){
      temp.push(item[0])
    }
  }
  for(let i=0;i<temp.length;i++){
    while(arr.includes(temp[i])){
      let index = arr.indexOf(temp[i])
      arr.splice(index,1)
    }
  }
  console.log(arr.join(''))
})

全部评论

相关推荐

10-25 22:20
门头沟学院 Java
代码飞升_不回私信人...:同学院本,个人亮点去了,打招呼里面的废话也去了,学院本就是路边一条,明天拉满然后该学还是学,小厂也行尽量先有一段实习。另外你的项目描述写的不好,具体列一下可被提问的点,然后量化一下指标或者收益吧
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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