With Comments: 4 lines Code in C++ 21ms!

  • 3
    // This is classical interview question
    // As we know, the same number XOR together will be 0,
    // So, XOR all of numbers, the result is the number which only appears once. 
    int s = 0;
    for (auto it = nums.begin(); it != nums.end(); it++)
    	s ^= *it;
    return s;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.