LeetCode:只出现一次的数字

C++示例程序:

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int length = nums.size();
        if (length == 0 || length == 2) 
            return 0;
        for (int i = 0; i < length - 1; i++) {
            nums[0] ^= nums[i + 1];
        }  
        return nums[0];
    }
};

猜你喜欢

转载自www.cnblogs.com/yiluyisha/p/9278516.html