My C++ (Modern) One Liner

  • 0
    class Solution {
        int singleNumber(vector<int>& nums) {
         return accumulate(begin(nums),end(nums),0,bit_xor<int>());   

    Uses accumulate to fold or reduce the array by applying a binary function which in this case is bit_xor and accumulates it to starting variable having value 0.

Log in to reply

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