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 ...
随机推荐
- jmeter多个接口测试
针对接口文档,进行对应接口设计,多个接口设计用例需要使用事物控制器. 1.通过登录接口提取sign值 发送一个登录请求,然后通过正则表达式提取该sign值 正则表达式的使用,我稍后会在下一个博文中详细 ...
- ASP.NET 内容管理系统CMS
一.Umbraco 项目地址: http://umbraco.org/ Umbraco是一个开放源码的CMS内容管理系统,基于asp.net建立,使用mssql进行存储数据. 使用Umbraco ,设 ...
- wordpress自定义菜单间添加分隔符
我们知道wordpress自定义菜单每个item是用<li></li>来固定的,那如果想在</li>加分隔符要如何操作呢?如下图所示.我们可以用PHP的str_re ...
- sql 查询哪些字段重复及(in和exict的区别)
select count(1),content_id,keyword_id from tb_content_keyword_relation group by content_id,keyword_i ...
- Linux内核Socket实现之------Socket创建(2) 文件描述符
转载请注明:http://blog.chinaunix.net/uid-20788636-id-4408276.html 1.2 sock_map_fd函数 在用户空间创建了一个socket后,返回值 ...
- iOS的事件派发
dispatchPreprocessedEventFromEventQueue 先定位:hittest * thread #1, queue = 'com.apple.main-thread', st ...
- 学习:STL_deque容器
deque容器: 功能:双端数组,可以对头端进行插入删除操作 deque与vector区别: 1.vector对于头部的插入删除效率低,数据量越大,效率越低 2.deque相对而言,对头部的插入删除速 ...
- webapi HttpGet标签
该标签可以指定路由如HttpGet["Test"],以前用的很顺,后来加了Area后,按照area/controller/Test的路径去访问报404,原因是HTTPGet指定路由 ...
- planAhead的启动时间较长
发现Xilinx planAhead的启动时间约需10秒钟.
- python 启动pydoc查看文档
启动pydoc查看文档 python3 -m pydoc -p 访问http://localhost:6789 或者查看官方文档:https://seleniumhq.github.io/seleni ...