Last active
August 29, 2015 14:22
-
-
Save cangoal/4d9ae1bc2b259eb2fbe4 to your computer and use it in GitHub Desktop.
LeetCode - Number of 1 Bits
This file contains hidden or 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
| 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