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

  • 0

    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.

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

  • 0

    @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.