Leetcode461. Hamming Distance不要太简单哦
来源:互联网 发布:泛微oa数据库 迁移 编辑:程序博客网 时间:2024/06/12 18:53
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.
class Solution {
public:
int hammingDistance(int x, int y) {
int num = 0;
for (int i = 0; i < 32; i++)
{
int val = 1 << i;
if (val > x && val > y) {
break;
}
if ((x & val) != (y & val)) {
num++;
}
}
return num;
}
};
0 0
- Leetcode461. Hamming Distance不要太简单哦
- [LeetCode461]Hamming Distance
- leetcode461. Hamming Distance
- leetcode461. Hamming Distance
- python--leetcode461 hamming distance
- LeetCode461 Hamming Distance JAVA题解
- LeetCode461 Hamming Distance java The Hamming distance between two integers is the number osoluotion
- LeetCode 简单操作 | 461. Hamming Distance
- leetcode(461) Hamming Distance 简单题
- Hamming Distance
- hamming distance
- hamming distance
- Hamming Distance
- Hamming Distance
- Hamming Distance
- Hamming Distance
- Hamming Distance
- Hamming Distance
- Step by Step,用JAVA做一个FLAPPYBIRD游戏(一)
- js 数据类型
- 读《石头剪刀布》总结与感想
- Java中ElementType源码
- VR中的9轴传感器(重力加速度/陀螺仪/磁力计).md
- Leetcode461. Hamming Distance不要太简单哦
- 最近写的一个存储过程
- 素数
- android studioGsonFormat插件以及遇到Plugin Error: GsonFormat threw an uncaught PluginException. Disable Pl
- centos搭建web环境
- 忘记密码模板
- Mysql安装问题一二
- django orm
- 论文阅读:Sparsifying Neural Network Connections for Face Recognition