🎉 One-stop destination for all your technical interview Preparation 🎉
class Solution {
public:
int hammingWeight(uint32_t n) {
return (__builtin_popcount(n));
}
};
int hammingWeight(uint32_t n){
int res = 0;
while(n){
n &= n - 1;
++ res;
}
return res;
}