题解 | #字符统计#

字符统计

https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0

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

void (async function () {
    let input = await readline();
    input = input.split("");
    let map = new Map();
    for (let e of input) {
        if (map.has(e)) {
            map.set(e, map.get(e) + 1);
        } else {
            map.set(e, 1);
        }
    }
    // console.log(map);
    let mapArray = Array.from(map.entries());
    // console.log(mapArray);
    mapArray.sort((a, b) => {
        if(a[1] === b[1]){
            return a[0].localeCompare(b[0])
        }
        else{
            return  b[1] - a[1]
        }
    } 
    )
    let res = mapArray.map((e) => e[0]).join('')
    console.log(res)
})();

全部评论

相关推荐

明天不下雨了:兄弟你是我今天看到的最好看的简历(我说的是简历风格跟简历书写)把985 211再搞亮一点。投boss就说;您好,我华科(985)研二在读,本科211。对您的岗位很感兴趣,希望能获得一次投递机会。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务