Hamming Distance

IF
AlgoAxiomStaff Engineers
JSTS
Easy20 mins

The [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) between two integers is the number of positions at which the corresponding bits are different.

Given two integers x and y, return the Hamming distance between them.

Examples

Example 1:

Input: x = 1, y = 4

Output: 2

Explanation:

`

1 (0 0 0 1)

4 (0 1 0 0)

↑ ↑

`

The two positions marked with have different bits.

Example 2:

Input: x = 3, y = 1

Output: 1

Constraints

  • 0 <= x, y <= 2^31 - 1
Source: Bitwise Manipulation pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle