LeetCode | 461. Hamming Distance 12_16
来源:互联网 发布:arduino 网络模块 编辑:程序博客网 时间:2024/06/15 10:05
The Hamming distance betweentwo integers is the number of positions at which the corresponding bits aredifferent.
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 correspondingbits are different.
水题,但是这题教会了我如何判断一个数字的二进制数里面有多少个1,这种方法记住了
class Solution {
public:
int hammingDistance(int x, int y) {
int c = x^y; int count = 0;
while(c>0)
{
if ((c & 1) == 1) count++;
c >>= 1;
}
return count;
}
};
阅读全文
0 0
- LeetCode | 461. Hamming Distance 12_16
- 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-461. Hamming Distance
- Leetcode 461. Hamming Distance
- LeetCode--461. Hamming Distance
- 461. Hamming Distance [LeetCode]
- [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 | 461. Hamming Distance
- 图文详解LinearLayoutManager填充、测量、布局过程
- MyBatis核心API测试
- 并行复制的从库执行FTWRL死锁
- SQL Server 2008 连接字符串
- 词频统计(30 分)(map vector sort)
- LeetCode | 461. Hamming Distance 12_16
- Uninformed search
- 数据结构实验之排序五:归并求逆序数
- 前辈分享的经典语句
- modem-rf代码调用分析,及调试
- NGUI滚动试图制作ScrollView
- pandas处理,填充缺失数据
- java集合框架(二)
- 树莓派入门(二)——设置静态IP