Sharing my 20ms C++ solution


  • 0
    T
    class Solution {
    public:
        int singleNumber(vector<int>& nums) {
            int result = 0;
            vector<int> count(32, 0);
            int i, j;
            for(i=0; i<32; i++)
                for(j=0; j<nums.size(); j++)
                {
                    count[i]+= 1&(nums[j]>>i);
                }
                
            for(i=0; i<32; i++)
            {
                if(count[i]%3 != 0)
                    result = result + (1<<i);
            }
            
            return result;
        }
    };

Log in to reply
 

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