Easy C solution


  • 0
    int hammingWeight(uint32_t n) {
        int bitOneCount = 0;
        int tmp;
        for(int i=0; i<32; i++){
            tmp = n>>i;
            tmp = tmp & 0x01;
            if(tmp==0x01){ 
                bitOneCount++;
            }
        }
        return bitOneCount;
    }
    

Log in to reply
 

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