Simple C++ solution (32 bit shifts)


  • 0
    D
    class Solution {
    public:
        int hammingWeight(uint32_t n) {
            int res=0;
            int i;
            for(i=0;i<32; i++) res += ((n>>i) & 0x01);
            
            return res;
            
        }
    };

Log in to reply
 

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