FIND AND ELIMINATE DUPLICATES IN AN ARRAY
namespace FindAndEliminateDuplicate
{
class Program
{
static void Main(string[] args)
{
int[] array = {2,3,5,3,6,8,2,6,6,3};
HashSet<int> holder = new HashSet<int>();
int[] newarray = new int[array.Length];
int j=0;
for (int i = 0; i < array.Length; i++)
{
if(holder.Contains(array[i]))
continue;
newarray[j++] = array[i];
holder.Add(array[i]);
}
for(int k=0;k<j;k++)
Console.WriteLine(newarray[k]);
}
}
}
No comments:
Post a Comment