O(n) using XOR in C++


  • 0
    G
    class Solution {
    public:
        int singleNumber(vector<int>& nums) {
            int ret = 0;
            for (int i = 0; i < nums.size(); i++) {
                ret ^= nums[i];
            }
            return ret;
        }
    };
    

Log in to reply
 

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