Last active
June 28, 2018 14:11
-
-
Save sreeprasad/db3426b20cc5161dfed25baf308f691e to your computer and use it in GitHub Desktop.
Find number of bits set with O(N) time where N is the total number of bits in the number
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
int findBitSet(int n){ | |
int count=0; | |
while(n>0){ | |
if(n&1 == 0) { | |
count++; | |
} | |
n=>>1; | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment