Geeks With Blogs
They call me Big Papa 4 kids and counting
Given a sorted list with duplicates, print out a list of just the unique elements.
For example:
Given (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9), the result would be (1, 3, 5, 9).

Here's one implementation:

int[] nums = new int[] { 1, 1, 1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 5, 5, 6, 9, 9, 9, 9 };
int n = 1;
Console.Write(nums[0]);
do
{
Console.Write(nums[n] == nums[++n] ? "" : nums[n].ToString());
} while (n < nums.Length);
Posted on Monday, October 1, 2007 8:04 AM Coding Challenge | Back to top


Comments on this post: Coding Challenge - Sorted Extraction

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © baileyrt | Powered by: GeeksWithBlogs.net