Leetcode 461. Hamming Distance JAVA语言
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语言相关推荐
- [LeetCode] 461. Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- LeetCode 461 Hamming Distance(汉明距离)
Q:The Hamming distance between two integers is the number of positions at which the corresponding bi ...
- LeetCode 461. Hamming Distance
题目: The Hamming distance between two integers is the number of positions at which the corresponding ...
- 【LeetCode】461. Hamming Distance (java实现)
2019独角兽企业重金招聘Python工程师标准>>> 原题链接 https://leetcode.com/problems/hamming-distance/ 原题 The Ham ...
- 461. Hamming Distance【数学|位运算】
2017/3/14 15:23:55 The Hamming distance between two integers is the number of positions at which the ...
- LeetCode之Hamming Distance
1.题目 The Hamming distance between two integers is the number of positions at which the corresponding ...
- LeetCode之461. Hamming Distance
------------------------------------------------------------------ AC代码: public class Solution {publ ...
- leetcode 461. 汉明距离(Java版)
题目 https://leetcode-cn.com/problems/hamming-distance/ 题解 使用 Java 中的按位异或 ^ 运算符:https://www.baeldung.c ...
- LeetCode(191 461):位1的个数 Number of 1 Bits 汉明距离 Hamming Distance(Java)
2019.9.14 #程序员笔试必备# LeetCode 从零单刷个人笔记整理(持续更新) github:https://github.com/ChopinXBP/LeetCode-Babel 之前在 ...
最新文章
- 推荐系统发展的六大影响因子 | 深度
- 关于SQL漏洞注入(Ado.Net)
- HashMap中ConcurrentModificationException异常解读
- MySQL日志分类及性能分析你应该知道的知识
- springcloud(七)-Feign声明式REST调用
- 关于Django中的数据库操作API之distinct去重的一个误传
- Linux 正则表达式基础
- 【CSP考前复习】关于考试时的注意事项
- python的基本概念_Python必学基础概念
- ffmpeg对H.264进行rtp打包
- dede rss.php,[经验]dede全站RSS订阅静态输出的办法
- 关于HTML条件注释你可能不知道的一些事儿
- 超硬核!小白读了这篇文章,就能在算法圈混了
- 今日download工程的奇怪问题error C2039: 'readStdErr' : is not a member of 'Programer',
- 移动端日历---纯**自己写的
- ESP8266-Arduino编程实例-MPL3115A2压力传感器驱动
- 开源软件 介绍及地址
- SSH公钥秘钥git
- [PHP代码审计]LightCMS1.3.7存在命令执行漏洞
- linux禁止root用户su,Linux 禁止普通用户su到root
热门文章
- nginx的配置和优化(隐藏版本号、gzip、expires、防盗链......等)
- Composer入门
- 石家庄地铁售票系统源码及截图(结对作业)
- 英特尔发现Spectre和Meltdown 补丁对性能影响程度为0-21%
- 我的WCF之旅(6):在Winform Application中调用Duplex Service出现TimeoutException的原因和解决方案...
- UVA 10214 Trees in a Wood
- 如何优化linux系统
- I.MX6 修改调试串口号(ttymx0 - ttymxc2)
- 前端问题多行点点点的问题
- hibernate笔记(三) Hibernate标识符属性(主键)生成策略全析