题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
// 使用HashSet可以避免重复值
Set<Integer> set = new HashSet<>();
for (int i = 0; i < n; i++) {
int num = sc.nextInt();
set.add(num);
}
sc.close();
// 使用TreeSet可以直接排序(接下来插入的数也会是有序的)
TreeSet<Integer> sortedSet = new TreeSet<>(set);
for (Integer num : sortedSet) {
System.out.println(num);
}
}
}
平安产险科技中心工作强度 22人发布