Single Line Functional style C++ Solution O(n)


  • 0
    I

    So the easiest way to do this is with std::accumulate and a lambda. Super expressive and if you know how lambda's work it's really readable.

    public:
        int singleNumber(vector<int>& nums) 
        {
            return std::accumulate(nums.begin(), nums.end(), 0, [](int x, int y) { return x^y; });
        }
    };
    

  • 0
    S

    @Insomniak47 can U explain it in detail? How it work?


Log in to reply
 

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