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

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

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

const readline = require("readline");

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


rl.on('line',function(data){
    let map = new Map();
    data.split("").forEach(item=>{
        if(map.get(item)){
            map.set(item,map.get(item)+1)
        }else{
            map.set(item,1)
        }
    });
    const numArr = []
    for(const [key,value] of map){
        numArr.push(map.get(key))
    }
    const reg = [];
    for(const [key,value] of map){
        if(value == numArr.sort()[0]){
            reg.push(key);
        }
    }
    const str = `[${reg}]`
    const regs = new RegExp(str, 'g')
    console.log(data.replace(regs,''))
});
#考研调剂#
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:10
直接上图
牛客13578115...:改得一般,不值80
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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