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. 使用iview 的表单组件验证 Upload 组件

    使用iview 的表单组件验证 Upload 组件 结果: 点击提交按钮, 没有填的form 项, 提示错误, 当填入数据后提示验证成功 代码: <template> <div id ...

  2. LeetCode——等差数列划分

    题目: 如果一个数列至少有三个元素,并且任意两个相邻元素之差相同,则称该数列为等差数列. 例如,以下数列为等差数列: 1, 3, 5, 7, 97, 7, 7, 73, -1, -5, -9 以下数列 ...

  3. oracle 12C的新特性-CDB和PDB

    1.前言 CDB与PDB是Oracle 12C引入的新特性,在ORACLE 12C数据库引入的多租用户环境(Multitenant Environment)中,允许一个数据库容器(CDB)承载多个可插 ...

  4. Redis主从配置以及哨兵模式

    Redis主从模式,应用写master,读slave,减轻master的压力. 配置主结点: daemonize yes port 6379bind 0.0.0.0 pidfile /opt/redi ...

  5. Linux——Session复制中的失败的可能原因之一

    组播地址问题 route add -net 224.0.0.0 netmask 240.0.0.0 dev eno16777728(自己的网卡名)

  6. 2019.9.27PHP基础

    PHP 基础语法规范: 1 <?php 开头 ?>结尾 2 php可以单独存在也可以和html等结合使用 3后缀名一般以.php结尾 php4,php5,php6,php7,phtml. ...

  7. 在vscode 中使用Git -- 已有项目添加到git

    本文使用与在已经存在本地项目的情况下将本地项目添加到git中管理,本地不存在项目则可以直接从Git上克隆下来后再创建项目目录更方便. 创建远程Git 仓库 如果Git 仓库已存在,可直接参考下一部,不 ...

  8. 【GitHub】命令行操作

    提交文件 本地修改之后:git add .     提交到暂存区 commit一下:git commit -m "xxx"   -m表示信息,不填无法commit 提交到远程仓库: ...

  9. hdu 1208 Ignatius and the Princess III 划分数,dp

    题目 题意:给你一个数字n,求将其划分成若干个数字相加总共有多少种划分数: <span style="font-size:24px;">#include <ios ...

  10. ar9331修改flash大小和df、cat /proc/mtd的区别

    首先感谢黄工的指导. 在openwrt固件目录下target/linux/ar71xx/image/Makefile,找到对应的机型,修改为4M,8M,16M,32M. 以oolite机型为例,如图所 ...