Simple c++ solution


  • 0
    A
    class Solution {
    public:`enter code here`
        int hammingWeight(uint32_t n) {;
            int res = 0;
            while(n)
            {
                if(n&1)
                    res++;
                n>>=1;
            }
            return res;
        }
    };

Log in to reply
 

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