1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-16 20:56:57 +02:00
CodeWars/6kyu/find_the_odd_int/solution.cs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

28 lines
441 B
C#

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