mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
34 lines
1.1 KiB
HTML
34 lines
1.1 KiB
HTML
<p>The <a href="https://en.wikipedia.org/wiki/Hamming_distance" target="_blank">Hamming distance</a> between two integers is the number of positions at which the corresponding bits are different.</p>
|
|
|
|
<p>Given two integers <code>x</code> and <code>y</code>, return <em>the <strong>Hamming distance</strong> between them</em>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> x = 1, y = 4
|
|
<strong>Output:</strong> 2
|
|
<strong>Explanation:</strong>
|
|
1 (0 0 0 1)
|
|
4 (0 1 0 0)
|
|
↑ ↑
|
|
The above arrows point to positions where the corresponding bits are different.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> x = 3, y = 1
|
|
<strong>Output:</strong> 1
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>0 <= x, y <= 2<sup>31</sup> - 1</code></li>
|
|
</ul>
|
|
|
|
<p> </p>
|
|
<p><strong>Note:</strong> This question is the same as <a href="https://leetcode.com/problems/minimum-bit-flips-to-convert-number/description/" target="_blank"> 2220: Minimum Bit Flips to Convert Number.</a></p>
|