Hamming distance swift solution


  • 0
    Z
    class Solution {
        func hammingDistance(_ x: Int, _ y: Int) -> Int {
            let result = x ^ y
            return String(result, radix: 2).characters.filter{ $0 == "1" }.count
        }
    }
    

Log in to reply
 

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