Skip to main content
LeetCode 461, Easy. Topics: Bit Manipulation. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:

Problem

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. Given two integers <code>x</code> and <code>y</code>, return <em>the <strong>Hamming distance</strong> between them</em>.

Examples

Constraints

  • 0 <= x, y <= 2^31 - 1
Note: This question is the same as 2220: Minimum Bit Flips to Convert Number.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026