My C solution in 4 ms


  • 0
    C

    int hammingWeight(uint32_t n) {
    int i=0;
    while((n+1)){
    n=n|(n+1);
    i++;
    }
    return 32-i;
    }


Log in to reply
 

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