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);