How about this?


  • -1
    T

    int hammingWeight(uint32_t n) {
    int k = 0;
    for( int i = 0; i != 32; ++i ){
    if( (n >> i) & 0x01 )
    ++k;
    }
    return k;
    }


Log in to reply
 

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