Hamming Distance


Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 98M

Authors:
Problem type
Allowed languages
Java 19

Description

The Hamming distance between two integers is the number of bit positions where the two numbers differ.

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

Explanation

Compute x XOR y , count how many bits are set to 1 in the result.
(補充:XOR 中文叫「互斥或」,意思是:兩個 bit 不一樣才會是 1,一樣就是 0)

Sample Input / Output

Sample Input Output
1 1 4 2
2 3 1 1

Comments

There are no comments at the moment.