题解:
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int[] a=new int[N];
HashSet<Integer> set=new HashSet<>();
for (int i = 0; i < N; i++) {
set.add(sc.nextInt());
}
int ret=0;
for(int i:set){
a[ret++]=i;
}
sort(a,0,ret-1);
System.out.println(ret);
for (int i = 0; i < ret; i++) {
System.out.print(a[i]+" ");
}
}
private static void sort(int[] a,int b,int e) {
int k=a[(b+e)/2];
int i=b;
int j=e;
while(i<=j){
while(a[i]<k)i++;
while(a[j]>k)j--;
if(i<=j){
int t=a[i];
a[i]=a[j];
a[j]=t;
i++;
j--;
}
}
if(b<j)sort(a,b,j);
if(i<e)sort(a,i,e);
}
}
原文:https://www.cnblogs.com/lijiahui-123/p/12309745.html