Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AndreyBespamyatnov/bf1d6e6d90e04f07c6f5 to your computer and use it in GitHub Desktop.
Save AndreyBespamyatnov/bf1d6e6d90e04f07c6f5 to your computer and use it in GitHub Desktop.
// You've got an array of ints 2,2,3,3,4,5,5... Find an element without a pair.
class Program
{
static void Main(string[] args)
{
var array = new int[] {2, 2, 3, 3, 4, 5, 5, 6, 9};
var array2 = new int[array.Length];
for (int index = 0; index < array.Length; index++)
{
var a = array[index];
var nxtIndex = index + 1;
if (nxtIndex == array.Length)
{
Console.WriteLine(a);
break;
}
var b = array[nxtIndex];
if (b != a)
{
Console.WriteLine(a);
}
else
{
index++;
}
}
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment