Simple C++ solution (4ms)


  • 2
    D
    int hammingWeight(uint32_t n) {
        
        int bitCount = 0;
        while(n != 0){
            bitCount += (n&1); 
            n = n >> 1;
        }  
        return bitCount;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.