My JavaScript solution, 7 Lines


  • 0
    M
    var hammingDistance = function(x, y) {
      let xor = (x ^ y).toString(2), res = 0
      for (let i of xor) {
        if (i === '1')  res ++
      }
      return res
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.