Finding Hamming Distance

Example 1

x = 9
y = 5
2
class Solution: 
def solve(self, x, y):
ans = 0
while x or y:
ans += (x & 1) ^ (y & 1) x >>= 1 y >>= 1
return ans

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store