Swift Solution


  • 1
    Z
    class Solution {
        func hammingDistance(_ x: Int, _ y: Int) -> Int {
            var xor = x ^ y
            var distance = 0
            while xor != 0 {
               distance += xor & 1
                xor >>= 1
            }
            return distance
        }
    }
    

Log in to reply
 

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