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.

PS:求海明距离。

思路:就是求x和y二进制的异或中的1的个数

public class Solution {public int hammingDistance(int x, int y) {// String x1=Integer.toBinaryString(x);// String y1=Integer.toBinaryString(y);int tem=x^y;int count=0;String str=Integer.toBinaryString(tem);for(int i=0;i<str.length();i++){if(str.charAt(i)=='1'){count++;}}// System.out.println(count);return count;}
}

转载于:https://blog.51cto.com/fulin0532/1888736

Leetcode 461. Hamming Distance JAVA语言相关推荐

  1. [LeetCode] 461. Hamming Distance

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

  2. LeetCode 461 Hamming Distance(汉明距离)

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

  3. LeetCode 461. Hamming Distance

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

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

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

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

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

  6. LeetCode之Hamming Distance

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

  7. LeetCode之461. Hamming Distance

    ------------------------------------------------------------------ AC代码: public class Solution {publ ...

  8. leetcode 461. 汉明距离(Java版)

    题目 https://leetcode-cn.com/problems/hamming-distance/ 题解 使用 Java 中的按位异或 ^ 运算符:https://www.baeldung.c ...

  9. LeetCode(191 461):位1的个数 Number of 1 Bits 汉明距离 Hamming Distance(Java)

    2019.9.14 #程序员笔试必备# LeetCode 从零单刷个人笔记整理(持续更新) github:https://github.com/ChopinXBP/LeetCode-Babel 之前在 ...

最新文章

  1. 推荐系统发展的六大影响因子 | 深度
  2. 关于SQL漏洞注入(Ado.Net)
  3. HashMap中ConcurrentModificationException异常解读
  4. MySQL日志分类及性能分析你应该知道的知识
  5. springcloud(七)-Feign声明式REST调用
  6. 关于Django中的数据库操作API之distinct去重的一个误传
  7. Linux 正则表达式基础
  8. 【CSP考前复习】关于考试时的注意事项
  9. python的基本概念_Python必学基础概念
  10. ffmpeg对H.264进行rtp打包
  11. dede rss.php,[经验]dede全站RSS订阅静态输出的办法
  12. 关于HTML条件注释你可能不知道的一些事儿
  13. 超硬核!小白读了这篇文章,就能在算法圈混了
  14. 今日download工程的奇怪问题error C2039: 'readStdErr' : is not a member of 'Programer',
  15. 移动端日历---纯**自己写的
  16. ESP8266-Arduino编程实例-MPL3115A2压力传感器驱动
  17. 开源软件 介绍及地址
  18. SSH公钥秘钥git
  19. [PHP代码审计]LightCMS1.3.7存在命令执行漏洞
  20. linux禁止root用户su,Linux 禁止普通用户su到root

热门文章

  1. nginx的配置和优化(隐藏版本号、gzip、expires、防盗链......等)
  2. Composer入门
  3. 石家庄地铁售票系统源码及截图(结对作业)
  4. 英特尔发现Spectre和Meltdown 补丁对性能影响程度为0-21%
  5. 我的WCF之旅(6):在Winform Application中调用Duplex Service出现TimeoutException的原因和解决方案...
  6. UVA 10214 Trees in a Wood
  7. 如何优化linux系统
  8. I.MX6 修改调试串口号(ttymx0 - ttymxc2)
  9. 前端问题多行点点点的问题
  10. hibernate笔记(三) Hibernate标识符属性(主键)生成策略全析