Skip to content

Instantly share code, notes, and snippets.

@dmnugent80
Last active August 29, 2015 14:13
Show Gist options
  • Save dmnugent80/54dd751884044a36f53a to your computer and use it in GitHub Desktop.
Save dmnugent80/54dd751884044a36f53a to your computer and use it in GitHub Desktop.
Return count of duplicated items in array
public int getCountDuplicates(int[] array){
HashSet<Integer> set = new HashSet<Integer>();
int dupCount = 0;
for (int i=0; i<array.length; i++){
if (!set.add(array[i]){
dupCount++;
}
}
return dupCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment