其他分享
首页 > 其他分享> > 汉明距离计算,非字符串

汉明距离计算,非字符串

作者:互联网

public int hammingDistance(int x, int y) {
int hamming = x ^ y;
int cnt = 0;
while(hamming > 0){
hamming = hamming & (hamming - 1);
cnt++;
}
return cnt;
}

char[] strChars = str.toCharArray();
char[] targetChars = target.toCharArray();
int count = 0;
for (int i = 0; i < 1280; i++) {
if (strChars[i] == targetChars[i]) {
count++;
}
}
return 1280-count;

标签:count,cnt,return,int,距离,++,hamming,汉明,字符串
来源: https://blog.51cto.com/1348916/2474162