pwstrick / daily

一份搜集的前端面试题目清单、面试相关以及各类学习的资料(不局限于前端)
2.39k stars 242 forks source link

汉明距离 #1034

Open pwstrick opened 4 years ago

pwstrick commented 4 years ago

461. 汉明距离

/**
 * @param {number} x
 * @param {number} y
 * @return {number}
 */
var hammingDistance = function(x, y) {
    let diff = x^y;
    return diff.toString(2).replace(/0/g, '').length;
};