class Solution { public: int totalHammingDistance(vector<int>& nums) { int res = 0; for (int i = 0; i < 32; i++) { int ones = 0; for (int n : nums) { if (n & (1 << i)) { ones++; } } res += ones * (nums.size()-ones); } return res; } };