Number of 1 bits solution

 avatar
unknown
c_cpp
a year ago
242 B
5
Indexable
class Solution {
public:
    int hammingWeight(uint32_t n) {
        int count = 0;

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