题解 | ## replaceAll

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

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

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    while(str = await readline()){
        let map = {}
        for(let i=0; i<str.length; i++) {
            let el = str[i]
            if (map[el]) {
                map[el] ++
            } else {
                map[el] = 1
            }
        }
        let min = Math.min(...Object.values(map))
        for (let el in map) {
            if (map[el] == min) {
                str = str.replaceAll(el, '')
            } 
        }
        console.log(str)
    }
}()

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
04-28 22:33
已编辑
门头沟学院 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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