Day 1 of 30-Day LeetCode Challenge

Given a non-empty array of integers, every element appears twice except for one. Find that single one.

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store