News


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);
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Comments

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: