s4553711
12/1/2017 - 2:52 PM

447.cpp

class Solution {
public:
    int totalHammingDistance(vector<int>& nums) {
        int total = 0;
        int n = nums.size();
        for(int i = 0; i < 32; i++) {
            int counter = 0;
            for(int j = 0; j < n; j++) {
                counter += (nums[j] >> i) & 0x01;
            }
            total += counter*(n - counter);
        }
        return total;
    }
};