```
class Solution {
public:
int totalHammingDistance(vector<int>& nums) {
if(nums.empty())
return 0;
array<int, 32> oneBitCounts{0};
for(int i : nums)
{
for(int bitNum = 0; i; ++bitNum)
{
oneBitCounts[bitNum] += (i & 1);
i >>= 1;
}
}
int distance = 0;
for(int i : oneBitCounts)
distance += ((nums.size() - i) * i);
return distance;
}
};
```