Leetcode 461. Hamming Distance
来源:互联网 发布:大数据 书 编辑:程序博客网 时间:2024/05/16 07:53
Leetcode 461. Hamming Distance
Difficulty:Easy
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.
//对两数异或,转为二进制后求1位的数目class Solution {public: int hammingDistance(int x, int y) { x^=y; vector<int> s; while(x!=0){ s.push_back(x%2); x/=2; } int r=0; for(int i=0;i<s.size();i++){ if(s[i]!=0) r++; } return r; }};
阅读全文
0 0
- 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
- [LeetCode]461.Hamming Distance
- spark--transform算子--mapPartitions
- 第七届福建省赛 【(5+2)/10】
- 发表在 Science 上的一种新聚类算法
- Crazy Learning for Day 18
- Java单例模式在多线程环境下的性能测试对比实验分析
- Leetcode 461. Hamming Distance
- 自定义View,自定义Switch样式
- GirdView的学习
- 《MNIST学习》读取数据
- Codeforces Round #423 (Div. 2) A&&B&& C
- 利用Bilibili的开源库ijkplayer实现视频直播
- 【Android日记】Mocky生成模拟接口,Postman模拟接口请求
- [LeetCode] 217. Contains Duplicate
- CodeForces 623B【质因子预处理+DP】