DEV Community

Discussion on: Coding Puzzles: Week of 4/8

Collapse
 
jellebekker profile image
Jelle Bekker

in c# using linq:

public static int Stray(int[] numbers)
{
    return numbers.Aggregate((x, y) => x ^ y);
}

or:

public static int Stray(int[] numbers)
{
    return numbers.GroupBy(x => x).Single(num => num.Count() == 1).Key;
}