Number of 1 bits solution

Anonymous
c_cpp
02/20/2024 12:39 PM
324 B
14
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