当前位置:网站首页>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
边栏推荐
- Game jam development cycle
- EMC Radiation Emission rectification - principle Case Analysis
- 理想L9正式发布:8月底前开始交付 零售价45.98万元
- 基于xposed框架hook使用
- C2-qt serial port debugging assistant 2021.10.21
- The neo4j skill tree was officially released to help you easily master the neo4j map database
- How to select the appropriate version of neo4j (version 2022)
- 【6. 高精度乘法】
- 【1. 快速排序】
- Graphacademy course explanation: Fundamentals of neo4j graph data science
猜你喜欢

Right and left vertical time axis with serial number

Li Kou today's question 1108 IP address invalidation

Latest release: neo4j figure data science GDS 2.0 and aurads GA

xpm_memory_tdpram原语的完整使用实例

JVM makes wheels

Official release of ideal L9: retail price of 459800 yuan will be delivered before the end of August

Database daily question - day 19: top ranked travelers

Penetration testing - logic vulnerability topic

ATM simulation system

Flink CDC MongoDB Connector 的实现原理和使用实践
随机推荐
智翔金泰冲刺科创板:年营收3919万亏损超3亿 拟募资40亿
June25,2022 PMP Exam clearance manual-3
[6. high precision multiplication]
GraphAcademy 课程讲解:《Neo4j 图数据科学简介》
Vscode custom template, take notes with the template?!
xpm_ memory_ A complete example of using the tdpram primitive
Starting WDA with tidevice
微软 IE 浏览器于 6 月 15 日被永久关闭
Use of day19qpushbutton 2021-10-30
Flash back when GoLand starts
Comprehensive interpretation by enterprise reviewers: enterprise growth of [State Grid] China Power Finance Co., Ltd
从数据库的分类说起,一文了解图数据库
Implementation differences between import and require in browser and node environments
Right and left vertical time axis with serial number
Day13QMainWindow2021-09-28
【4. 高精度加法】
Technical exploration: 360 digital subjects won the first place in the world in ICDAR OCR competition
The latest official product of domestic brand oppo! This ppt report! It really refreshes my understanding of it
Force buckle 141 Circular linked list
华阳智能冲刺深交所:拟募资4亿 复星惟盈是股东