laizimo / zimo-article

:books:博客——源于实践,乐于分享,欢迎Star~
1.06k stars 95 forks source link

leetcode算法题 #35

Closed laizimo closed 6 years ago

laizimo commented 6 years ago
  1. 海明距离(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

laizimo commented 6 years ago

这个部分已经被我转移到新项目中。项目地址