leetcode-easy-others-461. Hamming Distance
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的更多相关文章
- [LeetCode&Python] Problem 461. Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [Leetcode/Javascript] 461.Hamming Distance
[Leetcode/Javascript] 461.Hamming Distance 题目 The Hamming distance between two integers is the numbe ...
- LeetCode:461. Hamming Distance
package BitManipulation; //Question 461. Hamming Distance /* The Hamming distance between two intege ...
- Leetcode#461. Hamming Distance(汉明距离)
题目描述 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. 给出两个整数 x 和 y,计算它们之间的汉明距离. 注意: 0 ≤ x, y < 231. 示例: 输入: x = ...
- 【leetcode】461. Hamming Distance
problem 461. Hamming Distance solution1: 根据题意,所求汉明距离指的是两个数字的二进制对应位不同的个数.对应位异或操作为1的累积和. class Solutio ...
- 【LeetCode】461. Hamming Distance 解题报告(java & python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 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 汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- 4. leetcode 461. Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- 461. Hamming Distance(leetcode)
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
随机推荐
- ubuntu修改apt源
1.修改之前首先做好备份 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak 2.编辑源列表文件 sudo vim /etc/apt/sou ...
- 多Y轴示例
//多Y轴示例 <template> <div id="main" :style="{width:'1000px',height:'500px' }&q ...
- 用SVM处理XSS时,数据清洗打标数据标准化处理的方法和意义
def get_len(url): return len(url) def get_url_count(url): if re.search('(http://)|(https://)', url, ...
- 深入简出mysql--第一部分
第二章: 1.sql分类 DDL(Data Definition Languages)语句:数据定义语言,这些语句定义了不同的数据段.数据库.表.列.索引等数据库对象的定义. 常用的语句关键字主要包括 ...
- 免费FQ工具
这里使用免费的`梯子` 下载赛风 选择Windows下载 下载好之后,直接点击打开,它会自动连接,什么也不要设置,下载的就是一个exe文件,连接成功会打开一个网页,不用管
- python: 基本数据类型 与 内置函数 知识整理
列表 list.append(val) #末尾追加,直接改变无返回 list.inert(2,val) #插入到指定位置 list.extend(mylist1) #list会被改变 list2=li ...
- Delphi 子界类型
- 网络编程之套接字socket
目录 socket套接字 引子 为何学习socket一定要先学习互联网协议 socket是什么 套接字类型 基于文件类型的套接字家族 基于网络类型的套接字家族 套接字工作流程 基于TCP的套接字 简单 ...
- 使用SQL批量插入数据到数据库 以及一些SQL函数的语法
批量插入100条记录 set nocount on declare @i int=1; while @i<=100 begin Insert into Client(id,ClientCode, ...
- python selenium 执行完毕关闭chromedriver进程
#OS是我们操作dos系统时需要引入的库 import os #杀死这个chromedriver进程,因为每次启动都会打开,所以需要kill,这里用的chrome浏览器,打开方式时chromedriv ...