Same in c++. Single shifting and saving it to vector saves runtime drastically (55ms from 92ms).

class Solution { public: int totalHammingDistance(vector<int>& nums) { int tot=0; int size=nums.size(); int ones; for(int i=0; i< 32; i++){ ones=0; for(int j=0; j< size; j++){ ones+=nums[j] & 1; nums[j]>>=1; } tot+=ones*(size-ones); } return tot; } };Total Hamming Distance