C++ Solution (3ms)


  • 0
    I
    int hammingWeight(uint32_t n) {
            int num=0;
            while(n){
                num+=(n%2);
                n=n/2;
    //n>>=1;
            }
            return num;
        }
    

    if dividing the number by using >> operator taking the 6ms execution time


Log in to reply
 

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