mycode  92.05%

class Solution(object):
def hammingDistance(self, x, y):
"""
:type x: int
:type y: int
:rtype: int
""" n = x ^ y
cnt = 0
while n:
n = n&(n-1)
cnt += 1
return cnt

参考

class Solution(object):
def hammingDistance(self, x, y):
"""
:type x: int
:type y: int
:rtype: int
"""
res = x ^ y
res = bin(res)
return res.count("")

leetcode-easy-others-461. Hamming Distance的更多相关文章

  1. [LeetCode&Python] Problem 461. Hamming Distance

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

  2. [Leetcode/Javascript] 461.Hamming Distance

    [Leetcode/Javascript] 461.Hamming Distance 题目 The Hamming distance between two integers is the numbe ...

  3. LeetCode:461. Hamming Distance

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

  4. Leetcode#461. Hamming Distance(汉明距离)

    题目描述 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. 给出两个整数 x 和 y,计算它们之间的汉明距离. 注意: 0 ≤ x, y < 231. 示例: 输入: x = ...

  5. 【leetcode】461. Hamming Distance

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

  6. 【LeetCode】461. Hamming Distance 解题报告(java & python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 方法一:异或 + 字符串分割 方法二: ...

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

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

  8. [LeetCode] 461. Hamming Distance 汉明距离

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

  9. 4. leetcode 461. Hamming Distance

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

  10. 461. Hamming Distance(leetcode)

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

随机推荐

  1. Ngnx工作原理(1)

    Nginx 是一个轻量级的HTTP 服务程序,相比其他服务器程序如Apache,Nginx占用内存少,稳定性高,并发处理能力强.同时Nginx 还是一个反向代理服务程序,和邮件代理服务程序.Nginx ...

  2. cefsharp webBrowser Javascript 打开winForm界面

    在Cef webBrowser中,如果要调用 Javascript打开 一个 winForm界面,则需要使用  ShowDialog(),而不能使用 Show(),否则界面上的鼠标会转个不停

  3. RabbitMQ核心技术总结

    RabbitMQ和kafka类似,也是一个消息服务.RabbitMQ是轻量级的,易于部署在内部和云端.RabbitMQ支持多种消息协议,可以部署在分布式集群中,能够满足高规模,高可用性要求.Rabbi ...

  4. 微服务架构:构建PHP微服务生态

    微服务架构:构建PHP微服务生态   Linux系统技术交流QQ群(1675603)验证问题答案:刘遄 导读 诞生于 2014 年的“微服务架构”,其思想经由 Martin Fowler 阐述后,在近 ...

  5. NB-IOT双工模式

    半双工(Half Duplex)数据传输指数据可以在一个信号载体的两个方向上传输,但是不能同时传输.例如,在一个局域网上使用具有半双工传输的技术,一个工作站可以在线上发送数据,然后立即在线上接收数据, ...

  6. Zookeeper集群快速搭建

    Zookeeper集群快速搭建 1.cd /usr/local/zookeeper/conf(如在192.168.212.101服务器) mv zoo_sample.cfg zoo.cfg 修改con ...

  7. 基于nc命令监控服务端口的Shell脚本

    Shell代码: #!/bin/bash export LANG=en_US.UTF- #IP Address=127.0.0.1 #Port Port= #尝试的次数 n= #nc timeout, ...

  8. CSS3 文字渐变动画

    背景剪裁 语法:background-clip: border-box || padding-box || context-box || no-clip || text 本次用到的就是: -webki ...

  9. 《剑指offer》算法题第四天

    今日题目: 二进制中1的个数 数值的整数次方 调整数组顺序使奇数位于偶数前面 链表中倒数第K个节点 链表中环的入口节点 今天的题目都比较简单,但是前三道题都有不同的解法,4,5两题就不在这边讨论了,其 ...

  10. Visual Stdio C++ 编译器、链接器常用命令

    概览: cmd常用命令配合使用: del 删除指定文件 同erase cls 清屏 rd 删除空目录文件夹 dir 显示目录 cd 在当前盘符跳转指定目录(不同盘符跳转用盘符号)(分别表示根目录 上一 ...