题解 | #明明的随机数#

明明的随机数

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

输出条件:

  1. 有序(排序算法、TreeSet)
  2. 不重复(哈希表、TreeSet)
  3. 换行。。

已经很明显了,使用TreeSet实现最为简单、快捷并且不用写额外的算法或调用API

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        TreeSet<Integer> set = new TreeSet<>();
        int count = Integer.parseInt(sc.nextLine());

        for(int i = 0; i < count; i++){
            set.add(sc.nextInt());
        }
        for(int i : set){
            System.out.println(i);
        }
    }
}
全部评论

相关推荐

08-19 17:40
Java
吴offer选手:666 打老板了吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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