按位计算就行.

class Solution(object):
    def totalHammingDistance(self, nums):
        size, ans = len(nums), 0
        while True:
            zero= 0
            count=[0,0]
            for i in range(size):
                if nums[i] == 0:
                    zero += 1
                count[nums[i] % 2] += 1
                nums[i] >>= 1
            ans += count[0] * count[1]
            if zero == size:
                return ans

 

相关文章:

  • 2021-12-20
  • 2021-05-14
  • 2021-08-09
  • 2022-02-27
  • 2021-08-10
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案