92ms JavaScript bit operation solution


  • -1
    W
     var singleNumber = function(nums) {
        var digit=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
        //var digit=Array.apply(0,Array(32)).map(Number.prototype.valueOf,0);
        var result=0;
        for(var i=0;i<32;i++){
            for(var g=0;g<nums.length;g++){
                digit[i]+=((nums[g]>>i)&1);
            }
        }
        for(var j=0;j<32;j++){
            if(digit[j]%3!==0){
                result+=(1<<j);
            }
        }
        return result;
    };

Log in to reply
 

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