c++ solution


  • 0
    B
    class Solution {
    public:
        int totalHammingDistance(vector<int>& nums) {
            int result=0;
            long mask=1;
            while(mask<INT_MAX){
                int count=0;
                for(int i=0;i<nums.size();i++){
                    if(!(nums[i]&mask)) count++;
                }
                result+=(nums.size()-count)*count;
                mask<<=1;
            }
            
            return result;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.