Bite by bite check solution in Golang


  • 0
    O
    func hammingDistance(x int, y int) int {
    	res := 0
    	for {
    		if x+y == 0 {
    			break
    		}
    		if (x|1 == x) != (y|1 == y) {
    			res += 1
    		}
    		x >>= 1
    		y >>= 1
    	}
    	return res
    }
    

Log in to reply
 

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