[LeetCode] 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.
题意,两个数字转为二进制,然后异或一下,判断有多少个1
直接异或判断,简单粗暴
class Solution {private int ham(int num) {int sum = 0;while (num != 0) {if (num%2 == 1)sum ++;num = num/2;}return sum;}public int hammingDistance(int x, int y) {int res = x^y;return ham(res);} }
转载于:https://www.cnblogs.com/Moriarty-cx/p/9769685.html
[LeetCode] 461. Hamming Distance相关推荐
- Leetcode 461. Hamming Distance JAVA语言
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 ...
- LeetCode之Hamming Distance
1.题目 The Hamming distance between two integers is the number of positions at which the corresponding ...
- 461. Hamming Distance【数学|位运算】
2017/3/14 15:23:55 The Hamming distance between two integers is the number of positions at which the ...
- LeetCode之461. Hamming Distance
------------------------------------------------------------------ AC代码: public class Solution {publ ...
- LeetCode(191 461):位1的个数 Number of 1 Bits 汉明距离 Hamming Distance(Java)
2019.9.14 #程序员笔试必备# LeetCode 从零单刷个人笔记整理(持续更新) github:https://github.com/ChopinXBP/LeetCode-Babel 之前在 ...
- C#LeetCode刷题之#461-汉明距离(Hamming Distance)
问题 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. 给出两个整数 x 和 y,计算它们之间的汉明距离. 注意:0 ≤ x, y < 231. 输入: x = 1, y = ...
最新文章
- 2014 WAP校园招聘笔试题
- 另一种方法做本地reuse library的开发
- 终于有人把用户画像的流程、方法讲明白了
- layui流加载及传参
- 使用gridlayout布局后,因某些原因又删除,并整理文件夹结构时,Unable to resolve target #39;android-7#39;...
- 【刷题记录】GCJ 2.71~2.72
- 捷联惯导算法 matlab,捷联惯导算法与组合导航原理资料及更正
- linux hping3命令,系列H - hping3 - 测试网络及主机的安全 - 《Linux命令大全》 - 技术池(jishuchi.com)...
- python爬iptv直播源脚本_GitHub - bensonlai2002/iptv-m3u-maker: IPTV 国内+国外 电视台直播源m3u文件, 收集汇总本地源脚本...
- dell h330 不要做raid5 ,做raid0就可以了
- 成功三步曲:有勇、有谋、有德
- 如何把视频压缩到最小?请看详细步骤
- 2013年最火和最挣钱的IT职位
- JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
- Android手机直播系统开发介绍
- 给tensor增加维度 或 减少维度
- JDK、JER、JVM三者间的联系与区别
- php 浪漫代码,技术宅用代码表白也可以很浪漫
- 微软首席数字官亲述微软自己的数字化转型故事
- Kafka分区副本分配规则
热门文章
- Centos7手动安装OpenStack Mitaka版本--KeyStone安装
- Java多线程系列--“JUC原子类”01之 框架
- Java 线程池中的线程复用是如何实现的?
- Flink or Spark?实时计算框架在K12场景的应用实践
- 一个简单案例,5 分钟看懂 Java Lamdba 表达式
- Java注释@interface的用法【转】
- 实战:Nginx集成Lua脚本并调用memcached
- SIP协议和压力测试, SIP callflow图形生成
- 39.左值、左值引用、右值、右值引用
- Java final、static final 讲解