Should be pretty simple, go through the nth bit of each number, count the number of ones, and add to the return value the (number of ones)*(number of zeros)

```
class Solution {
public:
int totalHammingDistance(vector<int>& nums)
{
int ret = 0;
int s = nums.size();
for(int i=0;i<30;i++)
{
int ones = 0;
for(int j=0;j<s;j++)
{
if((nums[j]>>i)&1)
ones++;
}
ret+= (ones*(s-ones));
}
return ret;
}
};
```