477 Total Hamming Distance
Last updated
Was this helpful?
Last updated
Was this helpful?
Thebetween two integers is the number of positions at which the corresponding bits are different.
Now your job is to find the total Hamming distance between all pairs of the given numbers.
Example:
Note:
Elements of the given array are in the range of0
to10^9
Length of the array will not exceed10^4
.
这题只想到了brute force的方法,就是n方地两两求一个hamming distance。看了答案发现能够通过算每一位的diff,然后把它们加起来。