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 ...
随机推荐
- js 正则表达式2
对于某些特殊的字符,我们 必须转义一下才可以使用.(注意一点,我们使用那些需要转义的字符是通过"\"+相应的字符来构成的,记住是"\",而不也是"/& ...
- v-for给img的src动态赋值问题
做一个轮播图,给img赋值src <el-carousel-item v-for="(item, index) in carouselImgs" :key="ind ...
- C++传递不定参函数
定义不定参数函数,要用到下面这些宏: va_start(ap, farg): 初始化一个va_list变量ap,farg是第一个形参 va_arg(ap, type): 获取(下)一个type类型的参 ...
- Good Article Good sentence HDU - 4416 (后缀数组)
Good Article Good sentence \[ Time Limit: 3000 ms\quad Memory Limit: 32768 kB \] 题意 给出一个 \(S\) 串,在给出 ...
- 【C/C++】变量
变量定义就是告诉编译器在何处创建变量的存储,以及如何创建变量的存储.变量定义指定一个数据类型,并包含了该类型的一个或多个变量的列表. 变量声明向编译器保证变量以给定的类型和名称存在,这样编译器在不需要 ...
- ent 基本使用十六 聚合
ent 提供了聚合处理 一个group by + 聚合的处理(age以及name字段) package main import ( "context" "< ...
- 关于读取Com口数据时,Com口的名字的两种读法。
1,直接调用SerialPort类中的GetPortNames()方法. string[] portList = System.IO.Ports.SerialPort.GetPortNames(); ...
- python爬虫出现ProxyError: HTTPSConnectionPool错误
在今天刚刚打开pycharm运行爬虫时,发现所有的爬虫都不能运行,会出现如下的错误: 错误出现的主要原因是;代理错误(其实自己根本没有设置代理) 解决方法: 在网上查阅了许多类似的错误解决方法,试过后 ...
- linux高性能服务器编程 (二) --IP协议详解
第二章 IP协议详解 什么是IP协议:IP 协议是TCP/IP协议族的动力,它为上层提供了无状态.无连接.不可靠的服务. IP 头部信息:头部信息会出现在每一个IP数据报上,便于记录IP通信的源端IP ...
- 第08组 Alpha冲刺(5/6)
队名:955 组长博客:https://www.cnblogs.com/cclong/p/11898112.html 作业博客:https://edu.cnblogs.com/campus/fzu/S ...