利用TreeSet的有序性、无重复性:
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
Set<Integer> v = new TreeSet<>();
int n = sc.nextInt();
while (sc.hasNext()) v.add(sc.nextInt());
for(Integer i : v) System.out.printf("%d ", i);
}
}
京公网安备 11010502036488号