Skip to content

Instantly share code, notes, and snippets.

@CodyEngel
Created March 7, 2015 23:22
Show Gist options
  • Save CodyEngel/13b01dbc9b91f67a5fe3 to your computer and use it in GitHub Desktop.
Save CodyEngel/13b01dbc9b91f67a5fe3 to your computer and use it in GitHub Desktop.
Remove duplicate items from array, final answer
public static int[] removeDuplicates(int[] A)
{
int writeIndex = 0;
for (int i = 1; i < A.Length; i++)
{
if (A[writeIndex] != A[i])
{
writeIndex++;
A[writeIndex] = A[i];
}
}
for (int i = writeIndex + 1; i < A.Length; i++)
{
A[i] = 0;
}
return A;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment