Single Number

07/13/2016 Hash Table Bit Manipulation


Given an array of integers, every element appears twice except for one. Find that single one.


Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?


Result: Accepted Time: 8 ms

Here should be some explanations.

int singleNumber(int* nums, int numsSize) {
    int ans = 0;
    for(int i = 0; i < numsSize; i++)
        ans ^= nums[i];
    return ans;

Complexity Analytics

  • Time Complexity:
  • Space Complexity: