Created
March 7, 2015 23:22
-
-
Save CodyEngel/13b01dbc9b91f67a5fe3 to your computer and use it in GitHub Desktop.
Remove duplicate items from array, final answer
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
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