-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths2020_1.java
More file actions
40 lines (35 loc) · 796 Bytes
/
s2020_1.java
File metadata and controls
40 lines (35 loc) · 796 Bytes
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
33
34
35
36
37
38
39
40
package org.codingTest;
import java.io.*;
import java.util.*;
public class s2020_1 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashSet<Integer> hs = new HashSet<>();
List<Integer> list = new LinkedList<>();
int answer = 0;
for (int i = 0; i < n; i++) {
int num = sc.nextInt();
if (!hs.contains(num)) {
hs.add(num);
} else {
list.add(num);
}
}
answer = hs.size() - 1;
while (list.size() > 0) {
hs.clear();
int i = 0;
while (i < list.size()) {
if (!hs.contains(list.get(i))) {
hs.add(list.get(i));
list.remove(i);
}else {
i++;
}
}
answer += hs.size() - 1;
}
System.out.println(answer);
}
}