C++ solution using xor


  • 9
    X
    class Solution {
    public:
        int singleNumber(vector<int>& nums) {
            int res=0;
            for(auto num : nums)
                res ^= num;
            return res;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.