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

--

--

--

Lead, Product Development, Embedded System Specialist/Mad scientist

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Science Behind Success. What makes it so difficult?

Demystifying mathematics — One topic at a time — Quadratic Equations — Concept of sum/product of…

Two Myths of Numerical Integration, Debunked

The numerical of UNIVERSE

A Simple Proof of Fermat’s Little Theorem

Why Mathematics?

Errors We Make

Yellow ‘oops’ sign

Calculus: Continuity and Differentiability

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
Iqram Ali

Iqram Ali

Lead, Product Development, Embedded System Specialist/Mad scientist

More from Medium

Pure Vs Impure functions

The Difference Between Regular Functions and Arrow Functions

Coding Questions Series(1)

JavaScript Data Types