Number of 1 bits solution

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
242 B
1
Indexable
Never
class Solution {
public:
    int hammingWeight(uint32_t n) {
        int count = 0;

        while(n!= 0){
            if(n&1){
                count++;
            }
            n = n>>1;
        }
        return count;
    }
};
Leave a Comment