LeetCode Single Number

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

Note:

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

int singleNumber(int A[], int n) {
        int x;
        for(size_t i=0;i<n;++i)
        {
            x^=A[i];//异或两次同样的值为0,异或0为原值
        }
        return x;
    }


原文地址:https://www.cnblogs.com/yjbjingcha/p/6848686.html