【LeetCode】 461. Hamming Distance
2016-12-27 23:08
393 查看
The Hamming distance between two integers is the number of positions at which the corresponding
bits are different.
Given two integers
calculate the Hamming distance.
Note:
0 ≤
231.
Example:
public class Solution {
public int hammingDistance(int x, int y) {
return Integer.bitCount(x ^ y);
}
}
bits are different.
Given two integers
xand
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.
public class Solution {
public int hammingDistance(int x, int y) {
return Integer.bitCount(x ^ y);
}
}
相关文章推荐
- JavaScript-创建新数组
- CSS
- 关于储备(应急储备、管理储备、储备分析)的总结讨论
- MAC上反编译android apk---apktool, dex2jar, jd-jui安装使用(含手动签名)
- 【LeetCode】 459. Repeated Substring Pattern
- WCF服务的IIS托管(应用程序)
- C#多线程:深入了解线程同步lock,Monitor,Mutex,同步事件和等待句柄(中)
- 【JavaWeb】SSM+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(六)
- MVC实现局部视图刷新
- 【LeetCode】 455. Assign Cookies
- WCF服务的IIS托管(网站托管)
- 条款二十六:限制某个class所能产生的对象的数量
- MarkDown注册码
- WCF 大文件传输配置
- Java8中的default方法
- 钩子函数
- C#使用Protocol Buffer(ProtoBuf)进行Unity中的Socket通信
- Mac OSX网络诊断命令
- python中几个常见的黑盒子之“字典dict” 与 “集合set”
- html布局小练习(百度首页)