LeetCode:Hamming Distance
来源:互联网 发布:传世引擎源码 编辑:程序博客网 时间:2024/06/06 20:11
Total Accepted: 32005 Total Submissions: 45111 Difficulty: Easy Contributors: Samuri
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 = 4
Output: 2
Explanation:
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) { vector<int>result; int dst = x^y; while(dst) { if(dst%2==1) { result.push_back(dst%2); } dst/=2; } return result.size(); }};
0 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
- web前端_学习汇总
- fastboot
- AutoCompleteTextView —— 自动完成文本框
- 欢迎使用CSDN-markdown编辑器
- Android开发之----微信支付
- LeetCode:Hamming Distance
- Jenkins+GitLab+fir.im 持续集成
- C C++第三方库的使用以及报错提示未找到库文件的原因
- spring创建bean模式singleton与prototype的区别
- Android应用组件之Service
- python-re模块常用的函数及方法
- Java动态代理整理笔记
- 百万以内素数快速查找
- hdu 3018 Ant Trip (欧拉图+并查集)