Created
December 11, 2018 08:19
-
-
Save chygoz2/c735808d25876ddc0e773f0bf42fd642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int sockMerchant(int n, int[] ar) { | |
Set set = new HashSet<Integer>(); | |
int noOfPairs = 0; | |
for (int i=0; i<n; i++) { | |
if (set.contains(ar[i])) { | |
noOfPairs++; | |
set.remove(ar[i]); | |
} else { | |
set.add(ar[i]); | |
} | |
} | |
return noOfPairs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment