Skip to content

Instantly share code, notes, and snippets.

@johirbuet
Created May 31, 2018 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johirbuet/feeb43d44fccb738df6374df8460d9d3 to your computer and use it in GitHub Desktop.
Save johirbuet/feeb43d44fccb738df6374df8460d9d3 to your computer and use it in GitHub Desktop.
// 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