Skip to content

Instantly share code, notes, and snippets.

@SuryaPratapK
Created January 2, 2024 06:52
Show Gist options
  • Save SuryaPratapK/0a9421744408199d426e6f457e033777 to your computer and use it in GitHub Desktop.
Save SuryaPratapK/0a9421744408199d426e6f457e033777 to your computer and use it in GitHub Desktop.
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