DEV Community


Discussion on: Coding Puzzles: Week of 4/8

joshuagilless profile image
Joshua Gilless • Edited

@laurieontech did something really cool in JS with a bitwise XOR (her answer is above), so I figured I'd update this C++ answer with a bitwise XOR since I love it!

int stray(std::vector<int> numbers) {
    int r = numbers[0];
    for (int i = 1; i < numbers.size(); i++)
        r ^= numbers[i];
    return r;