WhiteYin / LeetcodeAnswer

leedcode解答,新手向
0 stars 0 forks source link

461. Hamming Distance #2

Open WhiteYin opened 6 years ago

WhiteYin commented 6 years ago

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Given two integers x and y, calculate the Hamming distance.

Note: 0 ≤ x, y < 231.

Example:

Input: x = 1, y = 4

Output: 2

Explanation:
1   (0 0 0 1)
4   (0 1 0 0)
       ↑   ↑

The above arrows point to positions where the corresponding bits are different.
WhiteYin commented 6 years ago

这种二进制的题目还是用位运算好点,速度能快30ms。可惜我不擅长这块。