汉明距离计算,非字符串
发表于:2024-11-24 作者:热门IT资讯网编辑
编辑最后更新 2024年11月24日,public int hammingDistance(int x, int y) {int hamming = x ^ y;int cnt = 0;while(hamming > 0){hamming
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;