leetcode算法题
laizimo opened this issue · comments
-
海明距离(Hamming distance)
**题目:**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.
**翻译:**两个整数之间的海明距离是在相应的位不同的位置数目。给两个整数x和y,计算海明距离
思路解析:可以通过将两个整数异或,然后计算二进制中的1的数目,即是海明距离。
位操作符详解:
&:按位与 |:按位或 ^:按位异或 >>:右移,相当于除2 >>:左移,相当于除3