C# program
Can someone please tell me the efficient code for extracting unique elements
from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) ->
(1, 3, 5, 9)
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Dec 28, 2009, 5:36 PM EST
Friend,
Here is your Solution Please check "Do you like this answer" check box if my answer helps you :) it helps me .
Thanks
int[] numArray = { 1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9 };
List<int> UniqElements = new List<int>();
UniqElements.Clear();
foreach (int i in numArray)
{
if (!UniqElements.Contains(i))
{
UniqElements.Add(i);
}
}
// Now Use it
foreach (int i in UniqElements)
{
Console.WriteLine(i.ToString());
}
Console.ReadKey();
Here is Output
---------------
Vishu4 reputationPosted Dec 28, 2009, 7:44 PM EST