Single Number

Given an array of integers A, every element appears twice except for one. Find that single one.
Thoughts
  • 0:00 The name is giving me no hint about what the question is about. Let's see how much time it will take.

  • 0:35 Solved it in 35 seconds. I missed superman though as I was too excited to write the time in these notes. DONE

int Solution::singleNumber(const vector<int> &A) {
    int res = 0;
    for(int x: A)
        res = res ^ x;
    return res;
}

Time Complexity: O(n)O(n)​

Space Complexity: O(1)O(1)​

Last updated