题解:使用LinkeHashSet可以保持原来顺序,又可以去重
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int[] a = new int[n];
for(int i = 0; i < n; i++){
a[i] = sc.nextInt();
}
sort(a);
}
}
public static void sort(int[] a){
Set<Integer> set = new LinkedHashSet<>();
for(int j = 0; j < a.length; j++){
set.add(a[j]);
}
for(Integer i : set){
System.out.print(i + " ");
}
}
}