LeetCode_461. Hamming Distance
461. Hamming Distance
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.
package leetcode.easy;
public class HammingDistance {
public int hammingDistance(int x, int y) {
return Integer.bitCount(x ^ y);
}
@org.junit.Test
public void test() {
System.out.println(hammingDistance(1, 4));
}
}
LeetCode_461. Hamming Distance的更多相关文章
- 【leetcode】461. Hamming Distance
problem 461. Hamming Distance solution1: 根据题意,所求汉明距离指的是两个数字的二进制对应位不同的个数.对应位异或操作为1的累积和. class Solutio ...
- [LeetCode] Total Hamming Distance 全部汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [LeetCode] Hamming Distance 汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- Total Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- 461. Hamming Distance and 477. Total Hamming Distance in Python
题目: The Hamming distance between two integers is the number of positions at which the corresponding ...
- LeetCode Total Hamming Distance
原题链接在这里:https://leetcode.com/problems/total-hamming-distance/ 题目: The Hamming distance between two i ...
- LeetCode Hamming Distance
原题链接在这里:https://leetcode.com/problems/hamming-distance/ 题目: The Hamming distance between two integer ...
- LeetCode:461. Hamming Distance
package BitManipulation; //Question 461. Hamming Distance /* The Hamming distance between two intege ...
随机推荐
- pace.js[转载]
pace.js监控了什么: pace.js对于加载进度监控了什么呢?通过阅读源码,我们看到整体的进度有四个部分组成:document,elements,eventLag和ajax这四种监视器(Moni ...
- 项目Beta冲刺(团队)——05.29(7/7)
项目Beta冲刺(团队)--05.29(7/7) 格式描述 课程名称:软件工程1916|W(福州大学) 作业要求:项目Beta冲刺(团队) 团队名称:为了交项目干杯 作业目标:记录Beta敏捷冲刺第7 ...
- Ruby——报错总结
前言 记录ruby的一些报错 错误 Could not find a valid gem 'pumagem' (>= 0) in any repository ERROR: Could not ...
- PID动图——很形象
p是控制现在,i是纠正曾经,d是管控未来! pid的公式: 其中Kp为比例带,TI为积分时间,TD为微分时间.PID控制的基本原理就是如此. pid的原理和代码,在木南创智的博客园中有很好的教程:ht ...
- Oracle执行过程中出现的问题
ORA-02292: 违反完整约束条件 (用户名.约束名) - 已找到子记录 造成原因:删除该表时,有依赖该表的子表数据,需要删除该条记录或者禁用约束. 查看约束所在的表:select * from ...
- Daily consumption
Bill record, standard of living, record every consumption, income, expenditure, manage your own life
- linux 打印当前工作目录
pwd
- 一个项目管理Master的心声
毕业第二年我被幸运女神所眷顾,一下成为了一个20多人研发团队的项目master,自己还未从职场菜鸟的称呼中走出来,就要开始管理团队,在接到通知的时候心里既兴奋又慌得六神无主,然而奔着初生牛犊不怕虎的精 ...
- VirtualBox support USB3.0 funciton
首先确认Oracle VM VirtualBox 的版本 然后通过如下链接下载对应的扩展增强包: http://download.virtualbox.org/virtualbox 再则,通过管理-& ...
- url的组成部分
/news/index.asp?boardID=5&ID=24618&page=1#name 协议:http: //为分隔符 域名:www.aspxfans.com :为域名和端口之间 ...