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

posted on 2017-05-10 16:29  Sempron2800+  阅读(123)  评论(0编辑  收藏  举报