-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-3-5.java
More file actions
32 lines (31 loc) · 1.04 KB
/
2-3-5.java
File metadata and controls
32 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
List<Integer> A = new ArrayList<>();
Map<Integer, Integer> D = new HashMap<>();
for (int i = 0; i < n; i++) {
int a = scanner.nextInt();
A.add(a);
D.put(a, D.getOrDefault(a, 0) + 1);
}
int mx = -1;
for (Map.Entry<Integer, Integer> entry : D.entrySet()) {
mx = Math.max(mx, entry.getValue());
}
List<Integer> answer = new ArrayList<>();
for (Map.Entry<Integer, Integer> entry : D.entrySet()) {
if (entry.getValue() == mx) {
answer.add(entry.getKey());
}
}
Collections.sort(answer);
for (int i = 0; i < answer.size(); i++) {
System.out.print(answer.get(i));
if (i < answer.size() - 1) {
System.out.print(" ");
}
}
}
}