Created
January 2, 2024 06:52
-
-
Save SuryaPratapK/0a9421744408199d426e6f457e033777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int hammingDistance(int x, int y) { | |
int xorVal = x^y; | |
int countSetBits = 0; | |
while(xorVal){ | |
if(xorVal & 1) | |
countSetBits++; | |
xorVal >>= 1; | |
} | |
return countSetBits; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment