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

 1 class Solution {
 2 public:
 3     int singleNumber(vector<int>& nums) {
 4         int size=nums.size();
 5         if(size==0||nums.empty())
 6             return 0;
 7         int res=0;
 8         for(int i=0;i<size;++i)
 9             res^=nums[i];
10         return res;
11     }
12 };

 

相关文章:

  • 2020-03-10
  • 2021-08-27
  • 2021-08-16
  • 2021-11-03
  • 2021-08-29
  • 2021-11-06
  • 2021-08-17
  • 2021-06-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-06-05
  • 2022-12-23
相关资源
相似解决方案