LeetCode 136 Single Number 数组中除一个数外其他数都出现两次,找出只出现一次的数
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 };