题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int first = sc.nextInt();
Map<Integer, Integer> map = new HashMap<>();
List<Integer> list = new ArrayList<>();
while (sc.hasNextInt()) {
int temp = sc.nextInt();
map.put(temp,map.getOrDefault(temp,0)+1);
}
for(Map.Entry<Integer,Integer> entry : map.entrySet()) {
list.add(entry.getKey());
}
Collections.sort(list);
for (int i : list) {
System.out.println(i);
}
}
}
使用hash表来保存状态
查看13道真题和解析