题解 | #明明的随机数#

明明的随机数

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

import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        while(in.hasNext()){
            solution1(in);
            // solution2(in);
        }
    }


    /**
     * TreeSet
     * @param in
     */
    private static void solution1(Scanner in){
        int N = in.nextInt();

        TreeSet<Integer> set = new TreeSet<>();

        for(int i=1; i<=N; i++){
            set.add(in.nextInt());
        }

        for(Integer num: set){
            System.out.println(num);
        }
    }


    /**
     * 位图
     * @param in
     */
    private static void solution2(Scanner in){
        int N = in.nextInt();

        int max = 500;
        int[] nums = new int[max+1];

        for(int i=1; i<=N; i++){
            nums[in.nextInt()] = 1;
        }
        
        for(int i=1; i<=max; i++){
            if(nums[i] == 1){
                System.out.println(i);
            }
        }
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 13:05
点赞 评论 收藏
分享
05-21 15:47
门头沟学院 Java
浪漫主义的虹夏:项目有亮点吗,第一个不是纯玩具项目吗,项目亮点里类似ThreadLocal,Redis储存说难听点是花几十分钟绝大部分人都能学会,第二个轮子项目也没体现出设计和技术,想实习先沉淀,好高骛远的自嗨只会害了自己
点赞 评论 收藏
分享
仁者伍敌:实习生要工作经验,工作要实习经验
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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