Q: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.
注:两个等长字符串之间的汉明距离(英语: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

S:
public class Solution {

      public int hammingDistance(int x, int y) {return Integer.bitCount(x ^ y);}

}

bitCount 自实现方案:

              int d = 0;int bitxor = x ^ y;while (bitxor > 0){if (bitxor % 2 == 1){d++;}bitxor = bitxor >> 1;}return d;

LeetCode 461 Hamming Distance(汉明距离)相关推荐

  1. LeetCode 461. Hamming Distance

    题目: The Hamming distance between two integers is the number of positions at which the corresponding ...

  2. Leetcode 461. Hamming Distance JAVA语言

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

  3. [LeetCode] 461. Hamming Distance

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

  4. C++ hamming distance汉明距离算法(附完整源码)

    hamming distance汉明距离的算法 hamming distance汉明距离的算法的完整源码(定义,实现,main函数测试) hamming distance汉明距离的算法的完整源码(定义 ...

  5. Hamming distance - 汉明距离

    Hamming distance - 汉明距离 1. Hamming distance //====================================================== ...

  6. 【LeetCode】461. Hamming Distance (java实现)

    2019独角兽企业重金招聘Python工程师标准>>> 原题链接 https://leetcode.com/problems/hamming-distance/ 原题 The Ham ...

  7. LeetCode之Hamming Distance

    1.题目 The Hamming distance between two integers is the number of positions at which the corresponding ...

  8. Hamming Distance汉明距离

    汉明距离是使用在数据传输差错控制编码里面的,汉明距离是一个概念,它表示两个(相同长度)字对应位不同的数量,我们以d(x,y)表示两个字x,y之间的汉明距离.对两个字符串进行异或运算,并统计结果为1的个 ...

  9. 461. Hamming Distance【数学|位运算】

    2017/3/14 15:23:55 The Hamming distance between two integers is the number of positions at which the ...

最新文章

  1. 8 pycharm 快捷键_Pycharm自动添加文件头注释和函数注释参数
  2. python入门指南 小说-Python 入门指南
  3. 基于WOA-SVM算法的乳腺肿瘤识别算法的MATLAB仿真
  4. 会计记忆总结之三:会计等式与复式记账
  5. 【活动】侬好上海,Microsoft Reactor来啦
  6. 基于MysqlConnector/C++的数据库连接池的实现
  7. SQL基础用法总结(以前复习的时候放在自己的新浪博客上)
  8. 字符串乘一个数_【思维拓展】三位数乘两位数,构造最大积和最小积
  9. 计算机进程调度论文,计算机操作系统小论文Linux进程调度.doc
  10. uint32是什么数据类型_C++编程基础: 4. 数据类型
  11. redhat 6.8 配置 centos6 163 的 yum 源
  12. 第2章[2.5] Ext JS组件、容器与布局
  13. linux把虚拟机上的文件共享,[转]windows中vmware虚拟机中的Linux如何进行文件的共享...
  14. 【备忘】于仕琪的libfacedetection相关
  15. 阿里巴巴的商品主图视频要怎么保存比较快
  16. PhotoShop 2022安装教程(附安装包)
  17. 为什么现在很多人想读博了?
  18. 看《吴峰光杀进 Linux 内核》
  19. 最小错误率的贝叶斯决策和最大似然比判别规则
  20. NEC the WISE点亮的不仅仅是新零售

热门文章

  1. python解释器有哪几种_Python解释器种类以及特点?
  2. python填充空值_python空值_python空值填充_python空值变量 - 云+社区 - 腾讯云
  3. 树莓派4b ros镜像 网盘_树莓派4B的入手操作
  4. 苹果4如何添加时间插件_苹果手机如何添加九键或26键输入法?iPhone怎样快速切换输入法?...
  5. 计算机开机显示器无显示桌面,电脑开机后显示器不亮故障排除方法
  6. [转]OpenCL 教学(一)
  7. Centos7 systemctl使用
  8. [BZOJ4815][CQOI2017]小Q的表格 数论+分块
  9. 腾讯 开源软件列表-开源中国社区
  10. 制作mac系统安装U盘