Reasonably fast JS solution


  • 1
    S

    I've seen the "clever" one-liners but I question performance. This is my solution that performs reasonably well. I'm sure there's somewhere I can save time but :)

    var hammingDistance = function(x, y) {
        let dist = 0
        let comb = x ^ y
        while (comb !== 0) {
            if (comb % 2) dist++
            comb >>= 1
        }
        return dist
    };
    

Log in to reply
 

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