Skip to content

Instantly share code, notes, and snippets.

@vmamore
Last active September 22, 2020 15:26
Show Gist options
  • Select an option

  • Save vmamore/2ff1f2f31f787244a8143c73ded30495 to your computer and use it in GitHub Desktop.

Select an option

Save vmamore/2ff1f2f31f787244a8143c73ded30495 to your computer and use it in GitHub Desktop.
static int sockMerchant(int n, int[] ar) {
var hashSet = new HashSet<int>();
int pairs = 0;
for(int i = 0; i < n; i ++){
if(!hashSet.Contains(ar[i])) {
hashSet.Add(ar[i]);
} else {
pairs++;
hashSet.Remove(ar[i]);
}
}
return pairs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment