477 Total Hamming Distance
TheHamming distancebetween 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 of
0
to10^9
Length of the array will not exceed
10^4
.
这题只想到了brute force的方法,就是n方地两两求一个hamming distance。看了答案发现能够通过算每一位的diff,然后把它们加起来。
Last updated