题解 | #字符统计#

字符统计

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

import java.util.*;

/**
 * @author hll[yellowdradra@foxmail.com]
 * @since 2023-04-01 10:59
 **/
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] chars = in.nextLine().toCharArray();
        Map<Character, Integer> counter = new HashMap<>(chars.length);
        for (char c : chars) {
            counter.compute(c, (k, v) -> v == null ? 1 : ++v);
        }
        Set<Map.Entry<Character, Integer>> set = new TreeSet<>((e1, e2) -> e2.getValue() - e1.getValue() == 0 ?
                e1.getKey() - e2.getKey() : e2.getValue() - e1.getValue()
        );
        set.addAll(counter.entrySet());
        set.forEach(e -> System.out.print(e.getKey()));
    }
}

全部评论

相关推荐

nbdy:字太多了,写简历不是写自传,亮点难点技能点列出来就行,要简明扼要
点赞 评论 收藏
分享
Cassifa:发的字比你都多的一律视为骗子或者想白嫖压榨实习生的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务