-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
29 lines (26 loc) · 760 Bytes
/
Solution.java
File metadata and controls
29 lines (26 loc) · 760 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
import java.util.*;
public class Solution {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int n = scan.nextInt();
int[] ar = new int[n];
for (int i = 0; i < ar.length; i++) {
ar[i] = scan.nextInt();
}
System.out.println(sockMerchant(n, ar));
scan.close();
}
private static int sockMerchant(int n, int[] ar) {
int count = 0;
Set<Integer> pairs = new HashSet<>();
for (int colour : ar) {
if (!pairs.contains(colour)) {
pairs.add(colour);
} else {
count++;
pairs.remove(colour);
}
}
return count;
}
}