Given an array of integers, every element appears twice except for one. Find that single one.
class Solution {
public:
int singleNumber(vector<int>& nums) {
sort(nums.begin(), nums.end());
for (int i =0; i<nums.size(); i++) {
if (nums[i]!=nums[i+1]) {
return nums[i];
}else{
i++;
}
}
return -1;
}
};