Total Hamming Distance
MediumBit Manipulation & Math
Decode it first. Clues, constraints, pattern and plan before any code.Return the sum of the Hamming distances (the number of differing bit positions) between every pair of numbers in nums.
nums = [4, 14, 2] → 6
4 = 0100, 14 = 1110, 2 = 0010
d(4, 14) + d(4, 2) + d(14, 2) = 2 + 2 + 2
nums = [4, 14, 4] → 4Constraints
1 <= nums.length <= 10^40 <= nums[i] <= 10^9- The answer fits in a 32-bit integer.