Same logic as in the editorial's solution, but use bit operators instead of arithmetic like sum and power


#1

public class Solution {

public int singleNumber(final List<Integer> A) 
{
    int checkBit=1;
    int result=0;
    int totalCheck=32;

    //Check each bit for each integer in the array
    while (totalCheck>0)
    {
        int count=0;
        for (int j:A)
        {
            //count number integers with '1' at the check bit
            if ((j&checkBit)!=0) count++;
        }
        
        //if it is not a multiple of 3, 
        //then it means the single number does contribute to the count of 1s
        //which means at the check bit, the single number is 1, so we make it 1 using OR
        if (count%3!=0) result|=checkBit;
        
        totalCheck--;
        checkBit<<=1;
    }
    
    return result;
}

}


#2

Does this soln work for negative inputs as well?