Simple JS solution using XOR


  • 0
    Y
    /**
     * @param {number[]} nums
     * @return {number}
     */
    var singleNumber = function(nums) {
        var result = 0;
        for(var i = 0; i < nums.length; i++){
            result = result ^ nums[i];      
        }
        
        return result
    };

Log in to reply
 

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