题解 | #序列中整数去重#
序列中整数去重
http://www.nowcoder.com/practice/6564a2f6e70f4153ad1ffd58b2b28490
题解:使用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 + " ");
}
}
}