LeetCode: Hamming Distance
来源:互联网 发布:打雷可以看网络电视 编辑:程序博客网 时间:2024/06/07 07:00
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 = 4Output: 2Explanation:1 (0 0 0 1)4 (0 1 0 0) ↑ ↑The above arrows point to positions where the corresponding bits are different.
Subscribe to see which companies asked this question.
int hammingDistance(int x, int y) { int d = 0; for (int i = 0; i < 32; ++i) { d += (x & 1) ^ (y & 1); x >>= 1; y >>= 1; } return d;}
1 0
- LeetCode 461. Hamming Distance
- 【Leetcode】461. Hamming Distance
- [LeetCode-461]Hamming Distance
- LeetCode 461. Hamming Distance
- [LeetCode]Hamming Distance
- Leetcode 461 Hamming Distance
- LeetCode - 461. Hamming Distance
- LeetCode-461. Hamming Distance
- Leetcode 461 Hamming Distance
- 【LeetCode】 461. Hamming Distance
- leetcode-461-Hamming Distance
- Leetcode Hamming Distance
- leetcode 461: Hamming Distance
- Leetcode-461. Hamming Distance
- leetcode--461 : Hamming Distance
- Leetcode 477: hamming distance
- Leetcode 461. Hamming Distance
- LEETCODE--Hamming Distance
- ios 项目目录结构
- Maven项目出现红叉,但是编译和运行都没错
- QT第一课_对话框小程序
- PHP学习之路
- CF:609C
- LeetCode: Hamming Distance
- 电子印章(图片)制作方法和步骤
- Kafka中的coordinator
- Mac下hadoop2.7 伪分布式安装
- Python线程进程
- c++中.dll与.lib文件的生成与使用的详解
- Context 都没弄明白,还怎么做 Android 开发?
- aitivity去掉标题栏
- 技术人从职场中脱颖而出的成长秘诀