首页 > 其他 > 详细

汉明距离计算,非字符串

时间:2020-02-28 12:08:35      阅读:70      评论:0      收藏:0      [点我收藏+]
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;

汉明距离计算,非字符串

原文:https://blog.51cto.com/1348916/2474162

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!