Number of 1 Bits
https://leetcode.com/problems/number-of-1-bits/submissions/
class Solution {
public:
int hammingWeight(uint32_t n) {
int count=0;
while(n>0){
if((n&1)>0){
count++;
}
n=n>>1;
}
return count;
}
};
class Solution {
public:
int hammingWeight(uint32_t n) {
int count=0;
while(n>0){
count++;
n=n&(n-1);
}
return count;
}
};
Comments
Post a Comment