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 ...
随机推荐
- docker之常用命令
1) docker run -p : --name mysql -v d:/docker/mysql/conf:/etc/mysql/conf.d -v d:/docker/mysql/logs:/l ...
- MySQL5.7修改数据库目录!
MySQL5.7默认安装,修改之前,停止MySQL服务. 数据库目录:C:\ProgramData\MySQL\MySQL Server 5.7\Data 配置文件:C:\ProgramData\My ...
- 抗D十招:十个方法完美解决DDoS攻击防御难题
可以说,DDoS是目前最凶猛.最难防御的网络攻击之一.现实情况是,这个世界级难题还没有完美的.彻底的解决办法,但采取适当的措施以降低攻击带来的影响.减少损失是十分必要的.将DDoS防御作为整体安全策略 ...
- Ubuntu与centos的区别小用法
给root设置密码 更新软件下载的地址 安装指令apt 使用ssh登录Ubuntu 使用ssh登录Ubuntu必须注意的地方,要先配置 sudo vi /etc/ssh/sshd_config 找到: ...
- LeetCode_Bit Manipulation
231. Power of Two Given an integer, write a function to determine if it is a power of two. class Sol ...
- dpkg -i libequinox-osgi-java_3.8.1-8_all.deb
dpkg -i libequinox-osgi-java_3.8.1-8_all.deb dpkg -i libequinox-osgi-java_3.8.1-8_all.deb https://ww ...
- 第二章 Vue快速入门-- 24 过滤器-Vue中全局过滤器的基本使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- 优化oracle读写任务
查读盘次数最多的前十个sql操作: SELECT * FROM (select PARSING_USER_ID, EXECUTIONS, SORTS, COMMAND_TYPE, DISK_READS ...
- poj1015 Jury Compromise[背包]
每一件物品有两个属性.朴素思想是把这两种属性都设计到状态里,但空间爆炸.又因为这两个属性相互间存在制约关系(差的绝对值最小),不妨把答案设计入状态中,设$f[i][j]$选$i$个人,两者之差$j$. ...
- jar启动名称示例
nohup java -jar -Dspring.profiles.active=20dev -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+Print ...