题解 | #明明的随机数#

明明的随机数

https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int first = sc.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        List<Integer> list = new ArrayList<>();
        while (sc.hasNextInt()) {
            int temp = sc.nextInt();
            map.put(temp,map.getOrDefault(temp,0)+1);
        }
        for(Map.Entry<Integer,Integer> entry : map.entrySet()) {
            list.add(entry.getKey());
        }
        Collections.sort(list);
        for (int i : list) {
            System.out.println(i);
        }
    }
}

使用hash表来保存状态

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-29 14:02
纠结的茶叶蛋在开会:太简单了,技术和业务没一个够用的,要么学业务,去搞erp或者his,要么专精技术,去搞架构
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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