Skip to content

Instantly share code, notes, and snippets.

@igorLisovitskiy
Created February 23, 2019 12:26
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 igorLisovitskiy/98f2e660eccc441754e00c3439803ef4 to your computer and use it in GitHub Desktop.
Save igorLisovitskiy/98f2e660eccc441754e00c3439803ef4 to your computer and use it in GitHub Desktop.
int[] arr = { 1, 2, 3, 4, 5, 6, 3, 2, 1 };
int[] duplicates = new int[arr.Length];
for (int j = 0; j < arr.Length; j++)
{
int counter = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[j] == arr[i])
{
counter++;
if (counter > 1)
{
duplicates[i] = arr[i];
}
}
}
}
WriteLine(string.Join(", ", duplicates));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment