1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 19:19:07 +01:00
CodeWars/6kyu/find_the_odd_int/solution.cs

29 lines
441 B
C#
Raw Normal View History

using System;
namespace Solution
{
class Kata
{
public static int find_it(int[] seq)
{
Array.Sort(seq);
int count = 1;
for (int i = 1; i < seq.Length; i++)
{
if (seq[i] == seq[i - 1]) count++;
else
{
if (count % 2 == 1) return seq[i - 1];
else count = 1;
}
}
if (count % 2 == 1) return seq[seq.Length - 1];
return -1;
}
}
}