Skip to content

Instantly share code, notes, and snippets.

@cangoal
Last active August 29, 2015 14:22
Show Gist options
  • Save cangoal/4d9ae1bc2b259eb2fbe4 to your computer and use it in GitHub Desktop.
Save cangoal/4d9ae1bc2b259eb2fbe4 to your computer and use it in GitHub Desktop.
LeetCode - Number of 1 Bits
public int hammingWeight(int n) {
int ret = 0;
while(n != 0){
n &= n-1;
ret++;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment