136. Single Number

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

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int res = 0;

        for(auto num:nums){
            res ^= num;
        }
        return res;
    }
};

results matching ""

    No results matching ""