Created
October 23, 2011 20:49
-
-
Save SeanPONeil/1307875 to your computer and use it in GitHub Desktop.
Method to detect duplicates in array of integers in Java
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
boolean detectDuplicates( int [] x){ | |
Set <Integer> intSet = new HashSet<Integer>(); | |
for( int i: x){ | |
if(intSet.contains(i)){ | |
return true; | |
} | |
intSet.add(i); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment