mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			863 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			863 B
		
	
	
	
		
			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>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>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>
 |