461. Hamming Distance

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 ≤ xy < 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的更多相关文章

  1. 【leetcode】461. Hamming Distance

    problem 461. Hamming Distance solution1: 根据题意,所求汉明距离指的是两个数字的二进制对应位不同的个数.对应位异或操作为1的累积和. class Solutio ...

  2. [LeetCode] Total Hamming Distance 全部汉明距离

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  3. [LeetCode] Hamming Distance 汉明距离

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  4. Total Hamming Distance

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  5. Hamming Distance

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  6. 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 ...

  7. LeetCode Total Hamming Distance

    原题链接在这里:https://leetcode.com/problems/total-hamming-distance/ 题目: The Hamming distance between two i ...

  8. LeetCode Hamming Distance

    原题链接在这里:https://leetcode.com/problems/hamming-distance/ 题目: The Hamming distance between two integer ...

  9. LeetCode:461. Hamming Distance

    package BitManipulation; //Question 461. Hamming Distance /* The Hamming distance between two intege ...

随机推荐

  1. Palisection(Codeforces Beta Round #17E+回文树)

    题目链接 传送门 题意 给你一个串串,问你有多少对回文串相交. 思路 由于正着做不太好算答案,那么我们考虑用总的回文对数减去不相交的回文对数. 而不相交的回文对数可以通过计算以\(i\)为右端点的回文 ...

  2. git在windows及linux(源码编译)环境下安装

    git在windows下安装 下载地址:https://git-scm.com/ 默认安装即可 验证 git --version git在linux下安装 下载地址:https://mirrors.e ...

  3. 微服务学习之路(三)——实现RPC远程服务调用

    RPC(Remote Producedure Call)调用原理:服务消费者称为客户端,服务提供者称为服务端,处于不同网络地址,需要建立网络连接.建立连接后,双方还必须按照某种约定的协议进行网络通讯— ...

  4. xunit.core 控制台输出日志

    参考链接: https://www.cnblogs.com/dudu/p/9391959.html http://landcareweb.com/questions/15813/xunit-netbu ...

  5. EJS的个人总结

    什么是模板引擎? 用于Web开发的模板引擎是为了使用用户界面与业务数据(内容)分离而产生的,使用模板语法编写的模板代码通常放在具有特的格式的文档中,经过模板引擎编译之后就会生成一个标准的HTML文档. ...

  6. (知识点1)#pragma once 与 #ifndef 解析

    例如 为了避免同一个文件被include多次,C/C++中有两种方式,一种是#ifndef方式,一种是#pragma once方式.在能够支持这两种方式的编译器上,二者并没有太大的区别,但是两者仍然还 ...

  7. 基本例程(4-1)手势识别C++ 和简单形状匹配

    扩展库https://blog.csdn.net/Taily_Duan/article/details/52130135 opencv3.3+扩展库 /************************ ...

  8. linux mustache bash 实现mo 做为docker容器运行动态配置工具数组的处理

    前面有说过关于使用mo 工具的简单配置使用,但是实际中我们可能存在比较复杂的数据处理,比如数组,mo 可以进行数组的处理,但是在测试的过程中,一直失败,查看了官方的demo以及帮助命令发现可以通过参数 ...

  9. LVS 的负载均衡调度算法

    LVS 的负载均衡调度算法 1.轮叫调度 (Round Robin) ( rr ) 调度器通过“ 轮叫 ”调度算法将外部请求按顺序轮流分配到集群的真实服务器上,它均等地对待每一台服务器,而不管服务器上 ...

  10. 【AtCoder】 ARC 096

    link C-Half and Half 题意:三种pizza,可以花\(A\)价钱买一个A-pizza,花\(B\)价钱买一个B-pizza,花\(C*2\)价钱买A-pizza和B-pizza各一 ...