My simple C++ solution O(n) run time and O(1) space


  • 6
    M

    class Solution {
    public:
    int singleNumber(vector<int>& nums) {

        int num = 0;
        
        for(int i=0;i<nums.size();i++)
        {
            num = num ^ nums[i];
        }
        
        return num;
        
    }
    

    };


Log in to reply
 

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