Single Number solution xor


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

Log in to reply
 

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