Skip to content

Instantly share code, notes, and snippets.

@johirbuet johirbuet/deDup.java
Created May 31, 2018

Embed
What would you like to do?
// Given an array of integers, remove all of the duplicates
int[] deDup(int[] a) {
Set<Integer> set = new LinkedHashSet<>();
for(int x : a) {
set.add(x);
}
int [] ret = new int[set.size()];
int i =0;
for(int x : set) {
ret[i++] = x;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.