首页 > 代码库 > LeetCode Single Number

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;
    }


LeetCode Single Number