Last active
August 29, 2015 14:13
-
-
Save dmnugent80/0d55cc1d9a84ea55b4b8 to your computer and use it in GitHub Desktop.
Delete Duplicates in an 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
//Delete duplicates in an array | |
public static int[] deleteDuplicates( int[] arrayWithDups ){ | |
ArrayList<Integer> arrayNoDups= new ArrayList<Integer>(); | |
for (int i=0; i < arrayWithDups.length; i++){ | |
if (!arrayNoDups.contains(arrayWithDups[i])){ | |
arrayNoDups.add(arrayWithDups[i]); | |
} | |
} | |
int[] arrayPrimitive = new int[arrayNoDups.size()]; | |
for (int i=0; i < arrayNoDups.size(); i++){ | |
arrayPrimitive[i] = arrayNoDups.get(i); | |
} | |
return arrayPrimitive; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment