利用TreeSet有序且不重复的性质,但是空间占用较大
public class Main{
public static void main(String[] args) { Scanner sc = new Scanner(System.in);
int num;
int k;
Set<Integer> set = new TreeSet<>();
while(sc.hasNext()){
num = sc.nextInt();
for(int i=0;i<num;i++){
k = sc.nextInt();
set.add(k);
}
Iterator<Integer> it = set.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
set.clear();
}
}
}