Skip to content

Instantly share code, notes, and snippets.

@chygoz2
Created December 11, 2018 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chygoz2/c735808d25876ddc0e773f0bf42fd642 to your computer and use it in GitHub Desktop.
Save chygoz2/c735808d25876ddc0e773f0bf42fd642 to your computer and use it in GitHub Desktop.
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