Answer the question
In order to leave comments, you need to log in
Is it possible to remove duplicate elements from an array with less code than me?
Is there a way to improve (using more advanced c# features) my algorithm?
int[] array = { 1, 2, 33, 44, 44,44,44 ,33, 22, 15 };
for (int i = 0; i < array.Length; i++)
{
for (int k = i+1; k < array.Length; k++)
{
if (array[i] == array[k])
{
array[i] = 0;
}
}
}
int[] numbers = new int[array.Length - array.Count(n => n == 0)];
int j = 0;
for (int i = 0; i < array.Length; i++)
{
if(array[i] != 0)
{
numbers[j] = array[i];
j++;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question