Last active
August 29, 2015 14:13
-
-
Save dmnugent80/54dd751884044a36f53a to your computer and use it in GitHub Desktop.
Return count of duplicated items in array
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
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