C++ partition based on bit status


#1
const int MODVAL = 1000000007;
int Solution::hammingDistance(const vector<int> &A) {
    int count = 0;
    for(int i=0; i<31; i++) {
        int setBit = 0, bitArr = (1<<i);
        for(auto it: A)
            setBit += ((it & bitArr) != 0);
        count = (count + setBit * (A.size()-setBit) * 2)%MODVAL;
    }
    return count;
}