Class Solution
java.lang.Object
g0401_0500.s0477_total_hamming_distance.Solution
477 - Total Hamming Distance.<p>Medium</p>
<p>The <a href="https://en.wikipedia.org/wiki/Hamming_distance" target="_top">Hamming distance</a> between two integers is the number of positions at which the corresponding bits are different.</p>
<p>Given an integer array <code>nums</code>, return <em>the sum of <strong>Hamming distances</strong> between all the pairs of the integers in</em> <code>nums</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [4,14,2]</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> In binary representation, the 4 is 0100, 14 is 1110, and 2 is 0010 (just showing the four bits relevant in this case). The answer will be: HammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [4,14,4]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>4</sup></code></li>
<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
<li>The answer for the given input will fit in a <strong>32-bit</strong> integer.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
totalHammingDistance
public int totalHammingDistance(int[] nums)
-