题解 | #明明的随机数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
用hashSet来解决这个问题
当然用TreeSet更快
import java.util.*;
/*
* */
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashSet<Integer> set = new HashSet<>();
for (int i = 0; i < n; i++) {
set.add(sc.nextInt());
}
//变成list来进行排序
ArrayList<Integer> list = new ArrayList<>(set);
Collections.sort(list);
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
}