[LeetCode&Python] Problem 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.
Example:
Input: x = 1, y = 4 Output: 2 Explanation:
1 (0 0 0 1)
4 (0 1 0 0)
↑ ↑ The above arrows point to positions where the corresponding bits are different.
Just need one line python code. (。・ω・。)
class Solution:
def hammingDistance(self, x, y):
"""
:type x: int
:type y: int
:rtype: int
"""
return bin(x^y).count('1')
[LeetCode&Python] Problem 461. Hamming Distance的更多相关文章
- [LeetCode&Python] Problem 821. Shortest Distance to a Character
Given a string S and a character C, return an array of integers representing the shortest distance f ...
- [LeetCode&Python] Problem 783. Minimum Distance Between BST Nodes
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...
- 【leetcode】461. Hamming Distance
problem 461. Hamming Distance solution1: 根据题意,所求汉明距离指的是两个数字的二进制对应位不同的个数.对应位异或操作为1的累积和. class Solutio ...
- [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 解题报告(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】477. Total Hamming Distance 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 位运算 日期 题目地址:https://leetco ...
随机推荐
- Oracle 12c Windows安装、介绍及简单使用(图文)
1.下载 地址为:http://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/index.html 含企业版和 ...
- rsync+inotify文件同步
rsync+inotify文件同步 在服务器中,通常结合计划任务.shell脚本来执行本地备份.为了进一步提高备份的可靠性,使用异地备份也是非常重要的,利用rsync工具,可以实现快速.高效的异地备份 ...
- Python 运算符重载
https://www.cnblogs.com/hotbaby/p/4913363.html
- 关于一致性hash详细
一致性哈希算法在1997年由麻省理工学院提出的一种分布式哈希(DHT)实现算法,设计目标是为了解决因特网中的热点(Hot spot)问题,初衷和CARP十分类似.一致性哈希修正了CARP使用的简 单哈 ...
- LeetCode--021--合并两个有序链表
问题描述: 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4 输出:1->1- ...
- 新手如何正确使用CLion之输出hello world
以前只使用过vc6.0,在用过jetbrain的pycharm后就考虑换个c++的编译器了,第一还是考虑了vs2017但用惯了色彩鲜艳的jb产品后竟然有点不习惯vs,最后还是果断选择了jb的CLion ...
- OAF在打开的新页面中添加按钮,功能是关闭当前页面
OAF在打开的新页面中添加按钮,功能是关闭当前页面 javascript:close()
- Oracle 12cR1中性能优化新特性之全数据库缓冲模式
通常情况下,Oracle会决定哪些数据会留在缓冲区中.当没足够的空间时,数据会被写出内存.此外,为了避免大量读取将有用的信息挤出缓冲区,Oracle对有些操作也许会才去绕过缓冲区的措施.Oracle1 ...
- ora2pg安装及卸载
--ora2pg安装 tar xzf ora2pg-10.x.tar.gz or tar xjf ora2pg-10.x.tar.bz2 cd ora2pg-10.x/ perl Makefile. ...
- CMD模拟http请求
搭建环境 前提是在win7中开启telnet服务 开启方法请参考:http://jingyan.baidu.com/article/870c6fc3cd6fa9b03fe4bee4.html 打开Te ...