leetcode477

public class Solution {
    public int TotalHammingDistance(int[] nums) {
        int total = 0, n = nums.Length;
            for (int j = 0; j < 32; j++)
            {
                int bitCount = 0;
                for (int i = 0; i < n; i++)
                {
                    bitCount += (nums[i] >> j) & 1;
                }
                total += bitCount * (n - bitCount);
            }
            return total;
    }
}

https://leetcode.com/problems/total-hamming-distance/#/description

原文地址:https://www.cnblogs.com/asenyang/p/6836641.html