My 3 lines C++ Solution using for_each


  • 2
     int singleNumber(vector<int>& nums) {
           int res = 0;
           for_each(nums.begin(),nums.end(),[&](int n){res ^=n;});
           return res;
       }
    

Log in to reply
 

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