当前位置:网站首页>Numbers that appear only once

Numbers that appear only once

2022-07-07 07:49:00 Free dreamer

This question examines the nature of XOR

Knowledge point : The same number is XOR 0, Because the other elements of this problem appear twice, you can pair XOR until there is only one XOR that appears only once

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

原网站

版权声明
本文为[Free dreamer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130648313951.html