当前位置:网站首页>Force buckle 461 Hamming distance
Force buckle 461 Hamming distance
2022-06-22 02:50:00 【SS_ zico】
- Hamming distance
In information theory , The Hamming distance between two equal length strings is the number of different characters in the corresponding position of two strings . let me put it another way , It is the number of characters needed to change a string into another string .
Brian · Kenigan algorithm
class Solution:
def hammingDistance(self, x, y):
xor = x ^ y
distance = 0
while xor:
distance += 1
# remove the rightmost bit of '1'
xor = xor & (xor - 1)
return distance
C++
class Solution {
public:
int hammingDistance(int x, int y) {
int res = x^y;
int c = 0;
while(res)
{
if(res&1 == 1)
c++;
res = res>>1;
}
return c;
}
};
// & Same as 1 Otherwise 0
// | There is one for 1 Then it is 1
// ^ The two values are different by 1 Same as 0
// << Left discard The right to repair 0
// >> On the right side of the discarded Left complement 0 Negative numbers make up 1
边栏推荐
- [pit encountered in docekr learning]
- [go language] we should learn the go language in this way ~ a comprehensive learning tutorial on the whole network
- Li Kou today's question 1108 IP address invalidation
- Sword finger offer 56 Delete duplicate nodes of the linked list
- xpm_memory_tdpram原语的完整使用实例
- ACL 2022 | multilingual knowledge map reasoning based on self supervised graph alignment
- Game Jam开发周期
- [9. submatrix sum]
- [6. high precision multiplication]
- GraphAcademy 课程讲解:《Neo4j 图数据科学基础》
猜你喜欢

【1. 快速排序】

Game jam development cycle

【一起上水硕系列】Day Two

All the knowledge you want to know about the PMP Exam is here

Day18qt signal and slot 2021-10-29

Using hook based on xposed framework
![[4. high precision addition]](/img/8c/1d07597b5ff3a573b453ac1ca19a5c.png)
[4. high precision addition]

【5. 高精度减法】

自动化工具-监测文件的变化

With the acceleration of industry wide digital transformation, what kind of storage will be more popular?
随机推荐
Right and left vertical time axis with serial number
Jz59. print binary tree in zigzag order
Starting WDA with tidevice
【3.整数与浮点数二分】
MySQL recursively finds the tree structure. This method is very practical!
Annual special analysis of China Mobile Banking in 2022
Is the link of Hengtai securities VIP low commission account opening safe?
UnionPay payment return merchant nignx post request 405
Deep Copy
【9. 子矩阵和】
Write the processing framework for playing
Graphacademy course explanation: Fundamentals of neo4j graph data science
【7. 高精度除法】
Flink CDC MongoDB Connector 的实现原理和使用实践
With the acceleration of industry wide digital transformation, what kind of storage will be more popular?
The latest official product of domestic brand oppo! This ppt report! It really refreshes my understanding of it
Sword finger offer 56 Delete duplicate nodes of the linked list
Two dot vertical progress styles
Day17QtQLcdNumber2021-10-22
Technical exploration: 360 digital subjects won the first place in the world in ICDAR OCR competition